#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 100 + 10;
int t[maxn], w[maxn], dp[maxn * maxn];
int main() {
  int n, sumt = 0, sumw = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &t[i], &w[i]);
    sumt += t[i];
    sumw += w[i];
  }
  memset(dp, 0, sizeof(dp));
  int minn = sumt;
  for (int i = 1; i <= n; i++) {
    for (int j = sumw; j >= w[i]; j--) {
      dp[j] = max(dp[j], dp[j - w[i]] + t[i]);
      if (j <= (sumt - dp[j])) minn = min(minn, (sumt - dp[j]));
    }
  }
  printf("%d\n", minn);
}
