#include <bits/stdc++.h>
using namespace std;
struct Node {
  int t;
  int w;
} node[110];
int dp[10010];
bool flag[210];
bool cmp(struct Node a, struct Node b) {
  if (a.w != b.w) return a.w > b.w;
  return a.t < b.t;
}
int main() {
  int n;
  while (cin >> n) {
    memset(dp, 0, sizeof(dp));
    memset(flag, 0, sizeof(flag));
    for (int i = 0; i < n; i++) scanf("%d%d", &node[i].t, &node[i].w);
    int sumt = 0, sumw = 0;
    int temp = 1e9;
    for (int i = 0; i < n; i++) {
      sumt += node[i].t;
      sumw += node[i].w;
      temp = min(temp, node[i].t);
    }
    flag[0] = 1;
    for (int i = 0; i < n; i++) {
      for (int j = sumt; j >= node[i].t; j--) {
        if (flag[j - node[i].t]) {
          dp[j] = max(dp[j], dp[j - node[i].t] + node[i].w);
          flag[j] = 1;
        }
      }
    }
    int ans = 1e9;
    for (int i = temp; i <= sumt; i++) {
      if (i >= sumw - dp[i] && flag[i]) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
