#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <stdio.h>

using namespace std;

bool cmp(pair<int, int> const& a, pair<int, int> const& b)
{
    return min(a.first, a.second) > min(b.first, b.second);
}

int main()
{
    FILE* fin = fopen("castle.in", "r");
    FILE* fout = fopen("castle.out", "w");
    int n, s;
    fscanf(fin, "%d%d", &n, &s);
    vector<pair<int, int>> g;
    g.reserve(n);
    long long ans = 0;
    for (int i = 0; i < n; i++)
    {
        int a, k;
        fscanf(fin, "%d%d", &a, &k);
        ans += a;
        g.push_back({a, k});
        bool f = a > k;
        a %= k;
        if (f && !a) {
            g.push_back({a, k});
        };
    }
    fclose(fin);
    sort(g.begin(), g.end(), cmp);
    for (auto cur: g)
    {
        if (s <= 0)
        {
            break;
        }
        //cout << s << ' ' << cur.first << ' ' << cur.second << endl;
        if (cur.first <= cur.second)
        {
            ans -= cur.first;
            s -= 1;
            continue;
        }
        else
        {
            int beat = cur.first / cur.second;
            //cout << "b: " << beat << endl;
            if (beat <= s)
            {
                ans -= (beat * cur.second);
                s -= beat;
                cur.first -= (beat * cur.second);
            }
            else
            {
                ans -= (s * cur.second);
                s = 0;
                cur.first -= (s * cur.second);
            }
        }
    }
    cout << ans << endl;
    fprintf(fout, "%ll", ans);
    fclose(fout);
    return 0;
}
