#include <bits/stdc++.h>
// mrrrowwww meeowwwww :3
// go play vivid/stasis! !! !!! https://vividstasis.gay
#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;
int ____init = []{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
return 0;
}();
int coins[500000];
bool has_coin[500000];
int main() {
int n, k; cin >> n >> k;
fo(i, 0, n) cin >> coins[i] >> has_coin[i];
int count = 0;
int sum = 0;
fo(i, 0, n) {
if (!has_coin[i] && sum + coins[i] < k && (i + 1 >= n || sum + coins[i] < coins[i + 1])) {
count++;
sum += coins[i];
}
}
cout << count << endl << k - sum << endl;
}