#define consfl 0
#define fname "castle"

#include <iostream>
#include <cstdio>
#include <cstdlib>

#include <algorithm>
#include <cmath>

#include <vector>

#define forn(i, n) for (int i = 0; i < n; i ++)
#define fornn(i, n, m) for (int i = n; i < m; i ++)

using namespace std;

const int dd = 1e5;

int a[dd], k[dd];

int main(){
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	if (!confl) {
		freopen(fname".in", "r", stdin);
		freopen(fname".out", "w", stdout);
	}
#endif
	int n, s;
	cin >> n >> s;
	int sum = 0;
	forn(i, n) {
		cin >> a[i] >> k[i];
		if (k[i] != 1) {
			cout << 3;
			exit(0);
		}
		sum += a[i];
	}
	cout << max(0, sum - s);
	return 0;
}