#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <cmath>

#pragma comment(linker, "/STACK:256000000")

using namespace std;

typedef long long int ll;
typedef long double ld;

const int MAX_N = 1000 * 100 + 5;

int n;
ll s;
ll arr[MAX_N];
ll at[MAX_N];

int main()
{
	freopen("castle.in", "r", stdin);
	freopen("castle.out", "w", stdout);

	scanf("%d %lld", &n, &s);

	ll answer = 0;

	for (int i = 0; i < n; ++i)
	{
		scanf("%lld %lld", &arr[i], &at[i]);
		answer += arr[i];
	}

	int max_at;
	ll at_max;
	while (s > 0)
	{
		max_at = 0;
		at_max = 0;
		for (int i = 0; i < n; ++i)
		{
			if (min(at[i], arr[i]) > at_max)
			{
				at_max = min(at[i], arr[i]);
				max_at = i;
			}
		}

		answer -= at_max;
		arr[max_at] -= at_max;
		--s;
	}

	printf("%lld", answer);

	fclose(stdin);
	fclose(stdout);

	return 0;
}