#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;

ifstream cin("castle.in");
ofstream cout("castle.out");

#define pb push_back
#define vec vector
#define rep(k, l, r) for (int k = (int)(l); k < (int)(r); k++)
typedef long long ll;
typedef pair<int, int> PII;

const int LIMIT = 1e9;
int main() {
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vec<int> a(n), k(n);
	int sum = 0;
	rep(i, 0, n) {
		cin >> a[i] >> k[i];
		sum += a[i];
	}

	vec<PII> arr;
	rep(i, 0, n) {
		if (a[i] >= k[i]) {
			arr.pb(PII(-k[i], a[i] / k[i]));
		}
		if (a[i] % k[i] != 0) { arr.pb(PII(-(a[i] % k[i]), 1)); }
	}
	sort(arr.begin(), arr.end());
	int am = 0;
	rep(i, 0, arr.size()) {
		if (am + arr[i].second > m) {
			sum += arr[i].first * (m - am); break;
		}
		else {
			sum += arr[i].first * arr[i].second;
			am += arr[i].second;
		}
	}
	cout << sum;

	return 0;
}