#include <bits/stdc++.h>
using namespace std;
int t[105];
int w[105];
int dp[105][50000];
int func(int idx, int diff) {
  if (idx == -1) return ((diff >= 20000) ? 0 : 0x3f3f3f3f);
  if (dp[idx][diff] != -1) return dp[idx][diff];
  return dp[idx][diff] = min(t[idx] + func(idx - 1, diff + t[idx]),
                             func(idx - 1, diff - w[idx]));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
    cin >> w[i];
  }
  memset(dp, -1, sizeof(dp));
  cout << func(n - 1, 20000);
  return 0;
}
