#include <bits/stdc++.h>
using namespace std;
const int MAXN = 128;
int N, sum, thick;
int used[MAXN];
int dn[MAXN * MAXN];
struct node {
  int x, y;
} ar[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> ar[i].x >> ar[i].y;
    sum += ar[i].y;
    thick += ar[i].x;
  }
  dn[0] = sum;
  for (int i = 1; i <= N; i++) {
    for (int j = 2 * N; j >= 0; j--)
      if (dn[j]) {
        if (dn[j + ar[i].x]) {
          if (dn[j + ar[i].x] > dn[j] - ar[i].y) {
            dn[j + ar[i].x] = dn[j] - ar[i].y;
          }
        } else {
          dn[j + ar[i].x] = dn[j] - ar[i].y;
        }
      }
  }
  dn[thick] = 1;
  for (int i = 1; i <= thick; i++)
    if (dn[i] && i >= dn[i]) {
      cout << i << endl;
      return 0;
    }
  return 0;
}
