#include <bits/stdc++.h>
using namespace std;
const long long int offset = 10000;
long long int dp[200][20005];
long long int solve(long long int a[][2], long long int n, long long int st,
                    long long int left) {
  if (st == n) {
    if (left >= 0) return 0;
    return 1e7;
  }
  if (dp[st][left + offset] != -1) return dp[st][left + offset];
  long long int ans = min(a[st][0] + solve(a, n, st + 1, left + a[st][0]),
                          solve(a, n, st + 1, left - a[st][1]));
  return dp[st][left + offset] = ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  memset(dp, -1, sizeof(dp));
  long long int a[n][2];
  for (long long int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1];
  cout << solve(a, n, 0, 0);
}
