#include <bits/stdc++.h>
const int oo = 1073741819;
using namespace std;
int f[200][500], n, t[500], w[500];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> t[i] >> w[i];
  memset(f, 61, sizeof(f));
  f[0][0] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= i * 2; j++) {
      if (j >= t[i]) f[i][j] = min(f[i][j], f[i - 1][j - t[i]]);
      f[i][j] = min(f[i][j], f[i - 1][j] + w[i]);
    }
  int ans = 1073741819;
  for (int j = 0; j <= n * 2; j++)
    if (f[n][j] <= j) ans = min(ans, j);
  cout << ans;
  return 0;
}
