#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <ctime>
#include <set>
#include <map>
#include <iomanip>
#include <cstdio>
#include <cstdlib>

using namespace std;

#define int long long
#define sz(a) (int)(a.size())

int n, s;
const int MAXN = 1e5 + 100;
pair<int, int> a[MAXN];
int k[MAXN];

bool cmp(pair<int, int> a, pair<int, int> b)
{
	return min(a.first, a.second) > min(b.first, b.second) ||
		(min(a.first, a.second) == min(b.first, b.second) && a.second > b.second);
}

bool cmp2(pair<int, int> a, pair<int, int> b)
{
	return a.second > b.second;
}

signed main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	freopen("castle.in", "r", stdin);
	freopen("castle.out", "w", stdout);
	cin >> n >> s;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i].second >> a[i].first;
	}
	sort(a + 1, a + n + 1, cmp);
	for (int i = 1; i <= n; ++i)
	{
		int z = a[i].second / a[i].first;
		if (z > 0)
		{
			if (z <= s)
			{
				a[i].second -= z * a[i].first;
				s -= z;
			}
			else
			{
				a[i].second -= s * a[i].first;
				s = 0;
			}
		}
		if (i + 1 <= n && s > 0)
		{
			if (a[i].second >= min(a[i + 1].first, a[i + 1].second))
			{
				a[i].second = 0;
				s -= 1;
			}
		}
		if (s == 0)
		{
			int ans = 0;
			for (int i = 1; i <= n; ++i)
			{
				ans += a[i].second;
			}
			cout << ans;
			return 0;
		}
	}
	sort(a + 1, a + n + 1, cmp2);
	for (int i = 1; i <= n; ++i)
	{
		if (s > 0 && a[i].second > 0)
		{
			a[i].second = 0;
			s -= 1;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		ans += a[i].second;
	}
	cout << ans;
	return 0;
}