#include <bits/stdc++.h>
using namespace std;
typedef struct book {
  int x;
  int y;
} book;
book b[120];
int sum, sum_a;
int dp[3000], n;
int ZeroOnePack(int v) {
  int i, j;
  dp[0] = 0;
  for (i = 1; i <= v; i++) {
    dp[i] = -0xffffff;
  }
  for (i = 1; i <= n; i++) {
    for (j = v; j >= b[i].x; j--) {
      if (dp[j] < (dp[j - b[i].x] + b[i].y)) {
        dp[j] = dp[j - b[i].x] + b[i].y;
      }
    }
  }
  if (v >= (sum_a - dp[v])) {
    return 1;
  }
  return 0;
}
bool cmp(book a, book c) {
  if (a.y != c.y)
    return a.y < c.y;
  else
    return a.x > c.x;
}
int main() {
  while (~scanf("%d", &n)) {
    sum = 0, sum_a = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &b[i].x, &b[i].y);
      sum += b[i].x;
      sum_a += b[i].y;
    }
    int ans, i;
    for (i = 1; i <= sum; i++) {
      ans = ZeroOnePack(i);
      if (ans == 1) {
        break;
      }
    }
    printf("%d\n", i);
  }
  return 0;
}
