#include <bits/stdc++.h>
using namespace std;
struct node {
  int t, w;
} e[101];
int f[201];
inline int read() {
  char ch = getchar();
  int f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  int x = 0;
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  int n = read(), sum = 0;
  for (register int i = 1; i <= n; ++i) {
    e[i] = (node){read(), read()};
    sum += e[i].t;
  }
  memset(f, 0x3f, sizeof(f));
  f[0] = 0;
  for (register int i = 1; i <= n; i++)
    for (register int j = sum; j >= e[i].t; j--)
      f[j] = min(f[j], f[j - e[i].t] + e[i].w);
  int ans;
  for (int i = sum; i >= 0; i--)
    if (sum - i >= f[i]) {
      ans = sum - i;
      break;
    }
  printf("%d\n", ans);
  return 0;
}
