#include <bits/stdc++.h>
using namespace std;
int n;
int h[101], k[101];
int sumh, sumk;
int f[201];
bool even_number = 1;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> h[i] >> k[i];
    sumh += h[i];
    sumk += k[i];
    if (h[i] == 1) {
      even_number = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = sumh; j >= h[i]; j--) {
      f[j] = max(f[j], f[j - h[i]] + k[i]);
    }
  }
  for (int i = 1; i <= sumh; i++) {
    if (even_number && f[i] == f[i - 1]) {
      continue;
    }
    if (sumk - f[i] <= i) {
      cout << i;
      return 0;
    }
  }
}
