#include <bits/stdc++.h>
using namespace std;
struct rec {
  int t, w;
} a[105];
int dp[205];
int main() {
  int n;
  int sum = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].t, &a[i].w);
    sum += a[i].t;
  }
  for (int i = 1; i <= n; i++)
    for (int j = sum; j >= a[i].t + a[i].w; j--)
      dp[j] = max(dp[j], dp[j - a[i].t - a[i].w] + a[i].t);
  cout << sum - dp[sum] << endl;
  return 0;
}
