#include <bits/stdc++.h>
struct book {
  int T, W;
};
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    struct book B[100];
    bool one = false;
    int DP[2001];
    int SumT, ans;
    SumT = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &B[i].T, &B[i].W);
      SumT += B[i].T;
      if (B[i].T == 1) one = true;
    }
    for (int i = 0; i <= SumT; i++) DP[i] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = SumT; j - B[i].T >= 0; j--) {
        if (DP[j - B[i].T] + B[i].W > DP[j]) DP[j] = DP[j - B[i].T] + B[i].W;
      }
    }
    for (ans = one ? 1 : 2; ans <= SumT; ans += one ? 1 : 2) {
      if (ans >= DP[SumT] - DP[ans]) break;
    }
    printf("%d\n", ans);
  }
  return 0;
}
