#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long base = 1e9 + 7;
const long long oo = 1e3 + 10;
long long n, m, k;
pair<long long, long long> a[oo];
long long res = 0;
string s1, s2;
void input() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second > 0 && b.second > 0)
    return a.first < b.first;
  else if (a.second < 0 && b.second < 0) {
    if (a.first != b.first)
      return a.first + a.second > b.first + b.second;
    else
      return a.second > b.second;
  } else
    return a.second > b.second;
}
long long f[102][60005];
void solve() {
  sort(a + 1, a + 1 + n, cmp);
  for (long long i = 1; i <= m; i++) f[0][i] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 60005; j; j--) {
      if (f[i - 1][j] > 0 && j >= a[i].first && j + a[i].second >= 0) {
        f[i][j + a[i].second] = max(f[i - 1][j + a[i].second], f[i - 1][j] + 1);
        res = max(res, f[i][j + a[i].second]);
      }
      f[i][j] = max(f[i][j], f[i - 1][j]);
      res = max(res, f[i][j]);
    }
  }
}
void ouput() { cout << res - 1; }
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (ifstream("test.txt")) {
    freopen("test.txt", "r", stdin);
  } else if (ifstream(""
                      ".inp")) {
    freopen(
        ""
        ".inp",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
  input();
  solve();
  ouput();
}
