#include <bits/stdc++.h>
using namespace std;
struct kdq {
  int x, y;
} a[1000];
int dp[1000][1000];
void solveb() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].x, &a[i].y);
    sum += a[i].x;
  }
  for (int i = 1; i <= sum; i++) dp[0][i] = 1 << 28;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < a[i].x; j++) dp[i][j] = dp[i - 1][j] + a[i].y;
    for (int j = a[i].x; j <= sum; j++)
      dp[i][j] = min(dp[i - 1][j - a[i].x], dp[i - 1][j] + a[i].y);
  }
  for (int i = 1; i <= sum; i++)
    if (i >= dp[n][i]) {
      cout << i;
      return;
    }
}
int main() {
  solveb();
  return 0;
}
