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

using namespace std;
const long long INF = 9 * 1e16;
vector<int> a;
vector<int> k;
vector<int> ind;

int get(int a, int k) {
    if (a % k == 0) return a / k - 1;
    return a / k;
}

int get2(int a, int k) {
    if (a % k == 0) return k;
    else return a % k;
}

bool cmp(int i, int j) {
    return get2(a[i], k[i]) >= get2(a[j], k[j]);
}

int main() {
    freopen("castle.in", "r", stdin);
    freopen("castle.out", "w", stdout);
    int n, s;
    cin >> n >> s;
    a.resize(n);
    k.resize(n);
    ind.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> k[i];
        ind[i] = i;
    }
    sort(ind.begin(), ind.end(), cmp);
   // vector<long long> s1(1, 0ll);
   // vector<long long> s2(1, 0ll);
    long long ss = 0;
    //vector<long long> s3(1, 0ll);
    for (int i = 0; i < n; i++) {
       // s1.push_back(s1.back() + get2(a[ind[i]], k[ind[i]]));
        //s2.push_back(s2.back() + get(a[ind[i]], k[ind[i]]));
        ss += a[ind[i]];
        //s3.push_back(s3.back() + a[ind[i]]);
    }
    cout << max(ss - s, 0ll) << "\n";
    /*long long ans = INF;
    for (int i = 0; i < n; i++) {
        if (s2[i + 1] > s) {
            for (int j = 0; j < n; j++) {
                ans = min(0ll + max(1ll * a[j] - 1ll * s * k[j], 0ll) + s3[n] - a[j], ans);
            }
            cout << ans << "\n";
            return 0;
        }
        else {
            //long long m = max(1ll + i - s + s2[i + 1], 0ll);
            long long m = max(min(min(s - s2[i + 1], 1ll + i), 0ll + n), 0ll);
            //cout << a[ind[i]] << " " << k[ind[i]] << " " << m << " " << s2[i + 1] << endl;
            //cout << s1[i + 1] << " " << s1[m] << endl;
            //cout << s1[i + 1] - s1[m] << " " << s3[n] - s3[i + 1] << " " << s3[n] << " " << s3[i + 1] << " " << i + 1 << " " << n << endl;
            ans = min(s1[i + 1] - s1[m] + s3[n] - s3[i + 1], ans);

        }
    }
    cout << ans << "\n";*/
    return 0;
}