#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

struct pt
{
	int a, k;
};
pt in[100];
int p[1000100]; int pn = 0;

int main()
{
	freopen("castle.in", "r", stdin);
	freopen("castle.out", "w", stdout);
	int n, s; scanf("%d%d", &n, &s);
	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		scanf("%d%d", &in[i].a, &in[i].k);
		ans += in[i].a;
		int a = in[i].a;
		int k = in[i].k;
		while (a)
		{
			p[pn] = -min(a, k);
			a += p[pn++];
		}
	}
	sort(p, p + pn);
	for (int i = 0; i < s && i < pn; ++i)
		ans += p[i];
	printf("%d", max(ans, 0));
	return 0;
}