#include <bits/stdc++.h>
using namespace std;
const int mx = 100 + 5, mj = 1e4 + 25, inf = 1e5;
int n, T = 0;
int w[mx];
int t[mx];
int dp[mx][mj];
int main() {
  int ans = 0, a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> w[i];
    T += t[i];
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= T; j++) {
      if (i == 0 && j == 0) {
        dp[i][j] = 0;
        continue;
      }
      if (i == 0) {
        dp[i][j] = inf;
        continue;
      }
      a = inf;
      if (j >= t[i]) a = dp[i - 1][j - t[i]];
      b = dp[i - 1][j] + w[i];
      dp[i][j] = min(a, b);
    }
  }
  for (int j = 0; j <= T; j++)
    if (dp[n][j] <= j) {
      cout << j;
      return 0;
    }
  return 0;
}
