#include <bits/stdc++.h>
long long mod = 1000000007;
using namespace std;
int n;
struct book {
  int t, l;
};
int dp[2][10002][201];
book b[1000];
bool cmp(book x, book y) {
  if (x.l == y.l) return x.t > y.t;
  return x.l > y.l;
}
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int func(int i, int wi, int ti) {
  if (i == n) {
    if (wi > ti) return 1000000;
    return 0;
  }
  if (dp[i][wi][ti] != -1) return dp[i][wi][ti];
  return dp[i][wi][ti] = min(b[i].t + func(i + 1, wi, ti + b[i].t),
                             func(i + 1, wi + b[i].l, ti));
}
int main() {
  int i, j, fl, test, sumt = 0, suml = 0;
  scanf("%d", &n);
  memset(dp, -1, sizeof(dp));
  for (i = 0; i < n; i++) {
    scanf("%d%d", &b[i].t, &b[i].l);
    sumt += b[i].t;
    suml = 0;
  }
  for (i = 0; i <= 10000; i++) {
    for (j = 0; j <= 200; j++) {
      if (i <= j)
        dp[n % 2][i][j] = 0;
      else
        dp[n % 2][i][j] = 1000000;
    }
  }
  int curr, prev, wi;
  for (i = n - 1; i >= 0; i--) {
    curr = i % 2;
    prev = (curr + 1) % 2;
    for (wi = 0; wi <= 10000 - b[i].l; wi++) {
      for (j = 0; j <= 200 - b[i].t; j++) {
        dp[curr][wi][j] =
            min(b[i].t + dp[prev][wi][j + b[i].t], dp[prev][wi + b[i].l][j]);
      }
    }
  }
  printf("%d\n", dp[0][0][0]);
  return 0;
}
