#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
int n;
int t[N], w[N], dp[N][2 * N];
int main() {
  cin >> n;
  int sumw = 0;
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> w[i];
    sumw += w[i];
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 1; j <= 2 * n; j++) dp[i][j] = -1e9;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 2 * n; j++) dp[i][j] = dp[i - 1][j];
    for (int j = 0; j <= 2 * n - t[i]; j++) {
      dp[i][j + t[i]] = max(dp[i][j + t[i]], dp[i - 1][j] + w[i]);
    }
  }
  int ans = 1e9;
  for (int i = 1; i <= 2 * n; i++) {
    if (sumw - dp[n][i] <= i) {
      ans = i;
      break;
    }
  }
  cout << ans << "\n";
}
