#include <bits/stdc++.h>
using namespace std;
struct book {
  int t, w;
} a[110];
int dp[210];
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    int i, j;
    int sum = 0;
    int res = 0;
    for (i = 0; i < n; i++) {
      scanf("%d%d", &a[i].t, &a[i].w);
      sum += a[i].t;
      res += a[i].w;
    }
    memset(dp, -1, sizeof(dp));
    int ans;
    dp[0] = 0;
    for (i = 0; i < n; i++)
      for (j = sum; j >= a[i].t; j--) {
        if (dp[j - a[i].t] != -1) dp[j] = max(dp[j], dp[j - a[i].t] + a[i].w);
      }
    for (i = 0; i <= sum; i++) {
      if (i >= res - dp[i]) {
        ans = i;
        break;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
