#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cassert>

#define rep(i, n) for (decltype(n) i = 0; i < n; i++)
#define dep(i, n) for (decltype(n) i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (decltype(b) i = a; i <= b; i++)
#define FORD(i, a, b) for (decltype(a) i = a; i >= b; i--)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()
typedef long long int64;
using namespace std;

const int maxn = 1e5 + 10;
int64 a[maxn], k[maxn];
int main()
{
	freopen("castle.in", "r", stdin);
	freopen("castle.out", "w", stdout);
	int64 n, s;
	cin >> n >> s;
	set<pair<int64, int> > q;
	rep(i, n)
	{
		cin >> a[i] >> k[i];
		q.insert({ min(a[i], k[i]), i });
	}
	int64 ans = 0;
	while (!q.empty())
	{
		auto x = *(--q.end());
		q.erase(--q.end());
		if (x.first >= a[x.second])
		{
			if (s > 0)
				s--, a[x.second] = 0ll;
		}
		else
		{
			int64 curx = a[x.second] / x.first;
			while (a[x.second] - x.first >= 0 && s > 0)
			{
				a[x.second] -= x.first;
				s--;
			}
			if (a[x.second] <= x.first)
				q.insert({ a[x.second], x.second });
		}
	}
	rep(i, n)
		ans += a[i];
	cout << ans << endl;
	return 0;
}