#include <bits/stdc++.h>
using namespace std;
int n, m, ans, nom, k, x, y, kol, sa, sb;
vector<pair<int, int> > a;
bool u[100000];
int f[10000];
int s = 0;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    a.push_back(make_pair(y, x));
    s += a[i].first;
  }
  u[0] = 1;
  for (int j = 0; j < n; j++)
    for (int i = 3000; i >= 0; i--)
      if (u[i] == 1) {
        if (u[i + a[j].second] == 0) {
          u[i + a[j].second] = 1;
          f[i + a[j].second] = f[i] + a[j].first;
        } else if (f[i + a[j].second] < f[i] + a[j].first) {
          f[i + a[j].second] = f[i] + a[j].first;
        }
      }
  for (int i = 0; i <= 3000; i++)
    if (u[i]) {
      if (i >= s - f[i]) {
        cout << i;
        return 0;
      }
    }
  return 0;
}
