infinite loop c++ with while and vector of pairs : <p>this program gives infinit loop when i try the input 
1
3 7
1 2
2 3
3 1
i run it manually and it seemed to me that it works , i can't understand why the while gives infinite loop (at least in this case of input)</p>

<pre><code>    #include &lt;iostream&gt;

    #include &lt;vector&gt;

#include &lt;algorithm&gt;
using namespace std;

int main()
{
    unsigned long long T,N , M ,p , m ;
    vector &lt;pair&lt;unsigned long long, unsigned long long &gt; &gt; v;
    cin&gt;&gt;T ;
    for  (unsigned long long i=0 ; i&lt;T;i++)
    {
        v={};
        cin&gt;&gt;N&gt;&gt;M ;
        for (unsigned long long j=0 ; j&lt; N ; j++)
        {
            cin&gt;&gt;p&gt;&gt;m ;
            v.push_back({p,m});

        }
        sort(v.begin(),v.end());

        while (M&gt;=v[0].second)
        {
            while (v[0].first&lt;=v[1].first)
            {
                v[0].first+=1 ;
                M-=v[0].second;

            }
            sort(v.begin(),v.end());

        }


    }
 cout&lt;&lt;"ans"&lt;&lt;v[0].first ;
}
</code></pre>

<p>can you please tell me what's wrong ??</p>
