#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long lg = 30;
const long long mod = 1e9 + 7;
pair<long long, long long> p[105];
long long n;
long long dp[105][10004];
long long rec(long long i, long long s) {
  if (i == n && s <= 0) return 0;
  if (i == n && s > 0) return INT_MAX;
  if (dp[i][s] != -1) return dp[i][s];
  long long ans = INT_MAX;
  ans = min(p[i].first + rec(i + 1, s - (p[i].second + p[i].first)),
            rec(i + 1, s));
  return dp[i][s] = ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
    sum += p[i].second;
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(0, sum);
}
