#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define fi(a, b) for (li i = a; i <= b; ++i)
#define fj(a, b) for (li j = a; j <= b; ++j)
#define dfi(a, b) for (li i = a; i >= b; --i)
#define mp make_pair

typedef long long li;
typedef pair<li, li> pl;

const li MAXN = 1e5 + 1;

pl c[MAXN], d[MAXN];
li x[MAXN], k[MAXN], a[MAXN];

int main() {
	freopen("castle.in", "r", stdin);
	freopen("castle.out", "w", stdout);
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	li n, s, sum = 0, ans = 0;

	cin >> n >> s;

	fi(0, n - 1) {
		cin >> a[i] >> k[i];
		c[i] = mp(k[i], i);
		x[i] = (a[i] % k[i] == 0) ? (a[i] / k[i]) : (a[i] / k[i] + 1);
		d[i] = mp(a[i] - x[i] * k[i] + k[i], i);
		sum += x[i];
	}

	sort(c, c + n);
	sort(d, d + n);

	li f = 0, g = 0;

	while (sum > s) {
		while (x[c[g].second] == 0)
			if (g == n)
				break;
			else
				++g;
		while (x[d[f].second] == 0)
			if (f == n)
				break;
			else
				++f;
		if (g == n) {
			ans += d[f].first;
			x[d[f].second]--;
			sum--;
			continue;
		}
		if (f == n) {
			li q = min(x[c[g].second], sum - s);
			x[c[g].second] -= q;
			sum -= q;
			ans += q * c[g].first;
			continue;
		}
		if (d[f] < c[g]) {
			ans += d[f].first;
			x[d[f].second]--;
			sum--;
		}
		else {
			li q = min(x[c[g].second], sum - s);
			x[c[g].second] -= q;
			sum -= q;
			ans += q * c[g].first;
		}
	}

	cout << ans;

	return 0;
}