#include <bits/stdc++.h>
using namespace std;
long long Set(long long n, long long pos) { return n | (1LL << pos); }
bool Check(long long n, long long pos) { return (bool)(n & (1LL << pos)); }
long long t[110], w[110];
long long dp2[110][210];
long long dp[110][210];
int main() {
  long long cs, ts, i, j, k, x, y, z, q, m, n, v;
  while (scanf("%lld", &n) != EOF) {
    long long sum = 0;
    for (i = 1; i <= n; i++) {
      scanf("%lld", &t[i]);
      scanf("%lld", &w[i]);
      sum += t[i];
    }
    dp2[0][0] = 0;
    for (long long pos = 0; pos <= n; pos++) {
      for (long long thick = 0; thick <= sum; thick++) {
        if (pos == 0 && thick) {
          dp2[pos][thick] = (1LL << 50);
          continue;
        }
        dp2[pos][thick] = dp2[pos - 1][thick];
        if (thick - t[pos] >= 0)
          dp2[pos][thick] =
              min(dp2[pos][thick], dp2[pos - 1][thick - t[pos]] + w[pos]);
      }
    }
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    long long ans = (1LL << 50);
    for (long long pos = 1; pos <= n; pos++) {
      for (long long thick = 0; thick <= sum; thick++) {
        dp[pos][thick] = dp[pos - 1][thick];
        if (thick - t[pos] >= 0) dp[pos][thick] |= dp[pos - 1][thick - t[pos]];
        if (pos == n && dp[pos][thick] && dp2[pos][sum - thick] <= thick)
          ans = min(ans, thick);
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
