#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rall(a) (a).rbegin(), (a).rend()

int main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cout.tie(nullptr);

	freopen("castle.in", "r", stdin);
	freopen("castle.out", "w", stdout);

	int n, s;
	cin >> n >> s;

	ll sm = 0;

	map<int, int> mp;

	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;

		mp[b] += a / b;
		sm += a;

		if (a % b) {
			mp[a % b]++;
		}
	}

	vector<pair<int, int> > arr;

	for (auto it : mp) {
		arr.push_back(it);
	}

	sort(rall(arr));

	for (int i = 0; i < (int)arr.size(); i++) {
		sm -= (ll)min(arr[i].second, s) * (ll)arr[i].first;
		s -= min(arr[i].second, s);
	}

	cout << sm << "\n";

	return 0;
}
