#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

const int sz = 1e5;

struct wall {
	long long a, k;
};

wall ar[sz];

bool comp(wall a, wall b) {
	return a.k > b.k;
}

priority_queue <long long> q;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	freopen("castle.in", "r", stdin);
	freopen("castle.out", "w", stdout);
	int n, s;
	scanf("%d%d", &n, &s);
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &ar[i].a, &ar[i].k);
		sum += ar[i].a;
	}
	sort(ar, ar + n, comp);
	for (int i = 0; s > 0 && i < n; i++) {
		long long seb = min(ar[i].a, ar[i].k);
		while (q.size() > 0 && q.top() > seb && s > 0) {
			sum -= q.top();
			q.pop();
			s--;
		}
		if (s < ar[i].a / ar[i].k) {
			sum -= s * ar[i].k;
			ar[i].a -= s * ar[i].k;
			s = 0;
		}
		else {
			sum -= (ar[i].a / ar[i].k) * ar[i].k;
			s -= ar[i].a / ar[i].k;
			ar[i].a -= (ar[i].a / ar[i].k) * ar[i].k;
		}
		q.push(ar[i].a);
	}
	while (q.size() > 0 && s > 0) {
		sum -= q.top();
		s--;
		q.pop();
	}
	printf("%lld", sum);
	return 0;
}

