#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <fstream>
using namespace std;
class wall
{
public:
    int a;
    int k;
    int r;
    int num;
};

bool operator<(wall a,wall b)
{

    return (a.k>b.k);
}

bool comp(wall a,wall b)
{
    return (a.r>b.r);
}
wall w[100100];
wall w2[100100];

wall f[100100];
int main()
{
    ifstream f1("castle.in");
    ofstream f2("castle.out");
    int n,s;
    f1 >> n >> s;
    for (int i=0; i<n; i++)
    {
        int a,k;
        f1 >> a >> k;
        wall w1;
        w1.a=a;
        w1.k=k;
        w1.num=i;
        w1.r=a%k;
        w[i]=w1;
        w2[i]=w1;
        f[i]=w1;
        //cout << '&' << w2.size() << endl;
    }

    sort(w,w+n);
    sort(w2,w2+n,comp);
    int res=0;
    int i1=0,i2=0;
    while (res<s)
    {
        if (i1==n&&i2==n){break;}
        if (i1==n){goto qw;}
        if (i2==n){goto wq;}
        if (w[i1].a==0&&w2[i2].a==0){break;}
        if (w[i1].a>w2[i2].r)
        {
            wq:
            if (res+w[i1].a/w[i1].k<=s){res+=w[i1].a/w[i1].k;w[i1].a=w[i1].r;f[w[i1].num].a=w[i1].r;i1++;}
        }else
        {
            qw:
            res++;
            f[w2[i2].num].a-=w2[i2].r;
            i2++;
        }
    }
    unsigned long long int sum=0;
    for (int i=0;i<n;i++){sum+=f[i].a;}
    f2 << sum;
    return 0;
}
