#include <bits/stdc++.h>
using namespace std;
int f[100 + 2][200 + 2];
void ff(int &a, int b) {
  if (a == -1 || a > b) a = b;
}
int main() {
  int t, w, n;
  while (cin >> n) {
    memset(f, -1, sizeof(f));
    f[0][0] = 0;
    for (int j = 0; j < n; j++) {
      cin >> t >> w;
      for (int i = 0; i <= 2 * n; i++) {
        if (f[j][i] != -1) {
          ff(f[j + 1][i + t], f[j][i]);
          ff(f[j + 1][i], f[j][i] + w);
        }
      }
      for (int i = 0; i <= 2 * n; i++)
        if (f[n][i] <= i && f[n][i] != -1) {
          cout << i << endl;
          return 0;
        }
    }
  }
}
