#include <bits/stdc++.h>
using namespace std;
const long long N = 250;
bool d[N];
int32_t main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> a(n + 1);
  long long sum = 0;
  long long fin = 0;
  for (long long i = 1; i <= n; ++i) {
    long long u, v;
    cin >> u >> v;
    a[i] = make_pair(u, v);
    sum += u;
    fin += v;
  }
  for (long long i = 1; i <= sum; ++i) {
    long long dp[n + 1][i + 1];
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for (long long j = 1; j <= n; ++j) {
      for (long long k = 0; k <= i; ++k) {
        if (a[j].first <= k && dp[j - 1][k - a[j].first] >= 0)
          dp[j][k] = max(dp[j - 1][k], dp[j - 1][k - a[j].first] + a[j].second);
        else
          dp[j][k] = dp[j - 1][k];
      }
    }
    if (i >= fin - dp[n][i]) d[i] = true;
  }
  long long ind = 0;
  for (long long i = 0; i <= sum; ++i) {
    if (d[i] == true) {
      ind = i;
      break;
    }
  }
  cout << ind << endl;
}
