cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second; sort(a + 1, a + n + 1); int ans = 0; priority_queue<int> Q; for (int i = 1; i <= n; ++i) { if (m < a[i].first) while (!Q.empty()) m += Q.top(), Q.pop(); if (m < a[i].first) break; if (m >= a[i].first + a[i].second) m -= a[i].second, Q.push(a[i].second), ans = max(ans, (int) Q.size()); elseif (!Q.empty() && a[i].second < Q.top()) Q.pop(), Q.push(a[i].second); } cout << ans << "\n"; return0; }