#include <bits/stdc++.h>
using namespace std;

int main() {
	freopen("castle.in", "r", stdin);
	#ifndef DEBUG
	freopen("castle.out", "w", stdout);
	#endif
	
	int n, s;
	scanf("%d%d", &n, &s);
	vector<int> a(n), k(n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &a[i], &k[i]);
	}
	set<pair<int, int>> ss;
	for (int i = 0; i < n; i++) {
		ss.insert({min(a[i], k[i]), i});
	}
	while (s > 0) {
		auto it = ss.end();
		if (it == ss.begin()) {
			break;
		}
		--it;
		int ind = it->second;
		if (it->first == k[ind]) {
			int cnt = min(s, a[ind] / k[ind]);
			s -= cnt;
			a[ind] -= cnt * k[ind];
			ss.erase(it);
			ss.insert({min(a[ind], k[ind]), ind});
		} else {
			a[ind] = 0;
			s--;
			ss.erase(it);
		}
	}
	
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
	}
	cout << sum << endl;
	
	return 0;
}
