#include <bits/stdc++.h>
using namespace std;
int n;
int t[200], w[200];
int f[200];
int sum = 0, s = 0;
int solve(int x) {
  f[0] = 0;
  for (int i = 1; i <= x; i++) f[i] = -12214019;
  for (int i = 1; i <= n; i++)
    for (int j = x; j >= t[i]; j--) f[j] = max(f[j], f[j - t[i]] + w[i]);
  return x >= (s - f[x]);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> w[i];
    sum += t[i];
    s += w[i];
  }
  for (int i = 1; i <= sum; i++)
    if (solve(i)) {
      cout << i << endl;
      break;
    }
  return 0;
}
