#include <bits/stdc++.h>
using namespace std;
long long a[10005], b[10005], f[1005];
int main() {
  long long n, tot = 0, t = 0;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", &a[i], &b[i]);
    tot += a[i];
  }
  for (int i = 1; i <= tot; i++) f[i] = 0x7f7f7f7f;
  f[0] = 0;
  for (int i = 0; i < n; i++)
    for (int j = tot; j >= a[i]; j--) f[j] = min(f[j], f[j - a[i]] + b[i]);
  for (int i = tot; i >= 0; i--)
    if (tot - i >= f[i]) {
      t = i;
      break;
    }
  printf("%lld", tot - t);
  return 0;
}
