#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>

using namespace std;
struct pa
{
    long long a,k;
};
pa a[200040];

bool comp1 (pa x, pa y)
{
    return (x.k > y.k);
}
int main()
{
    int  j,i,n,s;
    long long s2;
    freopen("castle.in","r",stdin);
    freopen("castle.out","w",stdout);

    j = 0;
    s2 = 0;
    scanf("%i%i",&n,&s);
    for (i = 0; i<n; i++)
    {
        int x,y;
        scanf("%i%i",&x,&y);
        s2 += x;
        if (x%y == 0)
        {
            a[j].a = x;
            a[j].k = y;
        }
        else
        {
            a[j].a = (x/y)*y;
            a[j].k = y;
            j++;
            a[j].a = x%y;
            a[j].k = a[j].a;
        }
        j++;
    }
    n = j;
    sort(a,a+n,comp1);
    for (i = 0; i<n; i++)
    {
        if (s >= a[i].a / a[i].k)
        {
            s -= a[i].a / a[i].k;
            s2 -= a[i].a;
        }
        else
        if (s > 0)
        {
            s2 -= a[i].k * s;
            s = 0;
        }
        else
            break;
    }
    cout << max(s2,s2-s2) << endl;


}
