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

#pragma comment(linker, "/stack:268435456")

#define ll long long
#define ld long double
#define sz(x) (int) x.size()
#define mp make_pair

#define TASKNAME "castle"

using namespace std;

int n, s;

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#else
	freopen(TASKNAME ".in", "r", stdin);
	freopen(TASKNAME ".out", "w", stdout);
#endif

	cin >> n >> s;
	ll all = 0;
	ll kill = 0;
	vector<pair<int, int>> q(n);
	for (int i = 0; i < n; i++) {
		cin >> q[i].second >> q[i].first;
		all += q[i].second;
	}

	sort(q.begin(), q.end());
	reverse(q.begin(), q.end());
	vector<ll> t;

	for (int i = 0; i < n; i++) {
		int g = q[i].second / q[i].first + bool(q[i].second % q[i].first);
		int k = min(g - 1, s);
		s -= k;
		ll killed = k * 1LL * q[i].first;
		kill += killed;
		t.push_back(min(q[i].second - killed, (ll) q[i].first));
	}

	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	
	for (int i = 0; i < sz(t); i++) {
		if (s > 0) {
			kill += t[i];
			s--;
		}
	}

	cout << max((ll)0, all - kill) << endl;

#ifdef _DEBUG
	while (1);
#endif
}