#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;

ifstream cin("castle.in");
ofstream cout("castle.out");

#define pb push_back
#define vec vector
#define rep(k, l, r) for (int k = (int)(l); k < (int)(r); k++)
typedef long long ll;

const int LIMIT = 1e9;

int main() {
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vec<int> a(n), k(n);
	int sum = 0;
	rep(i, 0, n) { 
		cin >> a[i] >> k[i]; 
		sum += a[i];
	}

	vec<int> arr;
	rep(i, 0, n) {
		while ((int)arr.size() < m && a[i] > 0) {
			if (a[i] > k[i]) {
				arr.pb(-k[i]); a[i] -= k[i];
			}
			else {
				arr.pb(-a[i]); a[i] = 0;
			}
		}
		if ((int)(arr.size() >= m)) { break; }
	}
	sort(arr.begin(), arr.end());
	rep(i, 0, min(m, (int)arr.size())) { sum += arr[i]; }
	cout << sum;

	return 0;
}