#include <bits/stdc++.h>
int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}
double nextDouble() {
  double x;
  scanf("%lf", &x);
  return x;
}
long long nextLong() {
  long long x;
  scanf("%I64d", &x);
  return x;
}
char nextChar() {
  char x;
  scanf("%c", &x);
  return x;
}
void newLine() { printf("\n"); }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long pow(long long a, long long b, long long MOD) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y);
      if (x > MOD) x %= MOD;
    }
    y = (y * y);
    if (y > MOD) y %= MOD;
    b /= 2;
  }
  return x;
}
int countSetBit(long long n) {
  int ans = 0;
  while (n != 0) {
    n -= (n & -n);
    ++ans;
  }
  return ans;
}
long long mod = 1ll * 1e9 + 7;
const int N = 100100;
const int M = 55;
const double eps = 1e-6;
using namespace std;
int a[111], b[111];
int dp[111][21111];
int n;
int solve(int i, int diff) {
  if (i == n) {
    if (diff >= 10000) {
      return 0;
    } else {
      return 1000000;
    }
  }
  int& ret = dp[i][diff];
  if (ret != -1) return ret;
  ret = 1000000;
  ret = min(ret, solve(i + 1, diff - b[i]));
  ret = min(ret, solve(i + 1, diff + a[i]) + a[i]);
  return ret;
}
int main() {
  cin >> n;
  int s = 0;
  for (int i = 0; i < n; i++) {
    a[i] = nextInt();
    b[i] = nextInt();
  }
  memset(dp, -1, sizeof dp);
  cout << solve(0, 10000) << endl;
}
