#include <bits/stdc++.h>
using namespace std;
const int64_t M = 1e2 + 5;
int64_t n, t[M], w[M], dp[M][20005], totalW;
int64_t solve(int64_t idx, int64_t wt) {
  if (idx > n) {
    if (wt >= 0) return 0;
    return 1e9;
  }
  if (dp[idx][1001 + wt] != -1) return dp[idx][1001 + wt];
  int64_t ans = t[idx] + solve(idx + 1, wt + t[idx]);
  ans = min(ans, solve(idx + 1, wt - w[idx]));
  return dp[idx][1001 + wt] = ans;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int64_t i = 1; i <= n; i++) cin >> t[i] >> w[i];
  memset(dp, -1, sizeof(dp));
  cout << solve(1, 0);
  return 0;
}
