#include <bits/stdc++.h>
using namespace std;
int dp[201];
int main() {
  int n, t, w, sumt = 0, sumw = 0;
  memset(dp, -1, sizeof(dp));
  dp[0] = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &t, &w);
    sumt += t;
    sumw += w;
    for (int j = 200; j >= t; j--) {
      if (dp[j - t] != -1) dp[j] = max(dp[j], dp[j - t] + w);
    }
  }
  int ans = sumt;
  for (int i = 0; i <= sumt; i++) {
    if (sumw - dp[i] <= i) {
      ans = i;
      break;
    }
  }
  printf("%d\n", ans);
}
