#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define endl        "\n"
#define pii         pair<int, int>
#define dint        long double

// tourist

bool cmp(pii a, pii b) {
    return (a.first + a.second < b.first + b.second);
}

const int inf = 1e18;

void solve() {
    int n; cin >> n;
    pii a[n+1];
    for(int i=1; i<=n; i++) {
        cin >> a[i].first >> a[i].second;
    }  
     // First -> Strenght, Second -> Weight
    sort(a+1, a+n+1, cmp);
    int dp[n+1][n+1];
    for(int i=0; i<=n; i++) for(int j=0; j<=n; j++) dp[i][j] = inf;
    dp[0][0] = 0;
    for(int i=0; i<n; i++) {
        for(int j=0; j<=i; j++) {
            int wt = dp[i][j];
            if(wt == inf) continue;
            dp[i+1][j] = min(dp[i+1][j], wt);
            if(wt <= a[i+1].first) {
                dp[i+1][j+1] = min(dp[i+1][j+1], wt + a[i+1].second);
            }
        }
    }
    int ans = 0;
    for(int i=0; i<=n; i++) {
        if(dp[n][i] != inf) {
            ans = i;
        }
    }
    cout << ans << endl;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;
    for(int i=1; i<=T; i++) {
        solve();
    }
    return 0;

}


#include <bits/stdc++.h>
using namespace std;

void recursive_comb(int *indexes, int s, int rest, function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

void foreach_comb(int n, int k, function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

int calc(string c) {
  int ret = 0;
  char lastOp = '+';
  for (int i = 0; i < c.size(); i++) {
    if (c[i] == '+') {
      lastOp = '+';
    } else if (c[i] == '-') {
      lastOp = '-';
    } else {
      int num = atoi(c.substr(i, 1).c_str());
      if (lastOp == '+') {
        ret += num;
      } else {
        ret -= num;
      }
    }
  }
  return ret;
}

int main() {
  // 入力
  vector<char> S(4);
  for (int i = 0; i < (int)S.size(); i++)
    cin >> S.at(i);
  
  int n = S.size() - 1;
  for (int k = 0; k <= n; k++) {
    foreach_comb(n, k, [S, n, k](int *indexes) {
      vector<char> op(n);
      for (int i = 0; i < n; i++) {
        op.at(i) = '+';
      }
      for (int i = 0; i < k; i++) {
        op.at(indexes[i]) = '-';
      }
      // 一つの文字列に連結
      string c = "";
      for (int i = 0; i < S.size(); i++) {
        c += S.at(i);
        if (i < op.size()) {
          c += op.at(i);
        }
      }
      // その文字列を計算する
      int ret = calc(c);
      if (ret == 7) {
        cout << c << "=" << ret << endl;
        exit(0);
      }  
    });
  }
}
