#include <bits/stdc++.h>
using namespace std;
int dp[110][10100];
bool f[110][10100] = {false};
int main() {
  int m, n, x, y, i, j, k, a[1111];
  pair<int, int> pii[101];
  cin >> n;
  for (i = 0; i < n; i++) cin >> pii[i].second >> pii[i].first;
  sort(pii, pii + n);
  for (i = 1; i <= n; i++)
    for (j = 0; j <= 10000; j++) dp[i][j] = 555555;
  reverse(pii, pii + n);
  f[0][0] = true;
  int t = 0;
  for (i = 0; i < n; i++) {
    x = pii[i].first;
    y = pii[i].second;
    for (j = 0; j <= t; j++)
      if (f[i][j]) {
        f[i + 1][j + y] = true;
        dp[i + 1][j + y] = min(dp[i + 1][j + y], dp[i][j] + y);
        if (dp[i][j] >= x) {
          f[i + 1][j - x] = true;
          dp[i + 1][j - x] = min(dp[i + 1][j - x], dp[i][j]);
        }
      }
    t += y;
  }
  int ans = 5555555;
  for (i = 0; i <= t; i++) ans = min(ans, dp[n][i]);
  cout << ans;
}
