#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<vector>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mk make_pair
#define ppb pop_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
#define forq(i, q, n) for(int i = 1; i < n; ++i)
#define all(a) a.begin(), a.end()
#define x first
#define y second

const int mod = 1e9 + 7;
const ll inf = 1e15 + 7;
const double eps = 1e-6;
const int maxn = 1e5 + 7;


vector<pii> a;

bool cmp(pii a, pii b)
{
	return a.y > b.y || a.y == b.y && a.x > b.x;
}

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;
	cin >> n >> s;
	forn(i, n)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		a.pb(mk(y, x));
	}
	sort(all(a));
	forn(i, n)
	{
		while (s && a[i].y > a[i].x)
			if (a[i].y > a[i].x)
			{
				s--;
				a[i].y -= a[i].x;
			}
	}
	sort(all(a), cmp);
	int i = 0;
	while (s)
	{
		while (a[i].x >= a[i].y && s)
		{
			s--;
			a[i].y = max(0, (a[i].y - a[i].x));
		}
	}
	int ans = 0;
	forn(i, n)
		ans += a[i].y;
	cout << ans;
	return 0;
}