#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
using namespace std;


typedef long long ll;
typedef vector < ll > vll;
typedef pair < ll, ll > pll;


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

	ll n, s;
	cin >> n >> s;
	multiset < pll > cast;
	multiset < ll > one;

	ll sum = 0;

	for (size_t i = 0; i != n; ++i) {
		ll a, k;
		cin >> a >> k;
		sum += a;
		if (a > k)
			cast.insert(pll(k, a));
		else
			one.insert(a);
	}

	ll ans = 0;

	while ((!cast.empty() || !one.empty()) && s != 0) {
		ll maxcast = -1, maxone = -1;
		multiset < pll > :: iterator tmp = cast.end();
		multiset < ll > ::iterator tmpone = one.end();

		pll p;
		if (!cast.empty()) {
			--tmp;
			p = *tmp;
			cast.erase(tmp);
		}
		else {
			p = pll(-1, 0);
		}

		if (!one.empty()) {
			--tmpone;
			maxone = *tmpone;
		}

		ll cnt;
		cnt = p.second / p.first;
		if (cnt > s)
			cnt = s;
		
		if (p.first < maxone) {
			s -= 1;
			ans += *tmpone;
			one.erase(tmpone);
			cast.insert(p);
		}
		else {
			ans += cnt * p.first;
			s -= cnt;
			if (p.first - cnt * p.second > 0) {
				one.insert(p.second - cnt * p.first);
			}
		}
	}
	cout << sum - ans << '\n';
}