#include <bits/stdc++.h>
using namespace std;
const long long N = 100000;
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
long long n, t[N], w[N], v, f[N];
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++) {
    t[i] = read(), w[i] = read();
    v += t[i];
  }
  memset(f, 0x3f3f3f, sizeof(f));
  f[0] = 0;
  for (long long i = 1; i <= n; i++)
    for (long long j = v; j >= t[i]; j--) f[j] = min(f[j], f[j - t[i]] + w[i]);
  for (long long i = v; i >= 0; i--) {
    if (v - i >= f[i]) {
      printf("%lld", v - i);
      break;
    }
  }
}
