#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

#define size(s) (ll) (s).size()
#define all(s) (s).begin(), (s).end()
#define rall(s) (s).rbegin(), (s).rend()

struct st {
	ll q, x, a, k, id;
};

bool comp(st a, st b) {
	return a.q < b.q || (a.q == b.q && a.x > b.x);
}

bool comp2(st a, st b) {
	return (a.a % a.k) < (b.a % b.k);
}

int main() {
	freopen("castle.in", "r", stdin);
	freopen("castle.out", "w", stdout);
	ll n, s, ans = 0;
	cin >> n >> s;
	vector<ll> a(2 * n), k(2 * n);
	vector<st> x(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i] >> k[i];
		a[i + n] = a[i] % k[i];
		a[i] -= a[i + n];
		x[i] = {min((a[i] / k[i]), s) * k[i], min(a[i] / k[i], s), a[i], k[i], i};
		x.push_back({a[i] % k[i], 1, -1, -1, i + n});
	}
	sort(rall(x), comp);
	for (ll i = 0; i < size(x); i++) {
		if (s - x[i].x >= 0) {
			ans += a[x[i].id] - x[i].q;
			s -= x[i].x;
		} else {
			ans += a[x[i].id] - s;
			s = 0;
		}
	}
	cout << ans << '\n';
    return 0;
}

