#include <bits/stdc++.h>
using namespace std;
int sum[105], sum2[105], f[105][100010], a[105][2];
int main() {
  int n, i, j, ans = 2000000000;
  cin >> n;
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &a[i][0], &a[i][1]);
    sum[i] = sum[i - 1] + a[i][1];
    sum2[i] = sum2[i - 1] + a[i][0];
    f[i][0] = f[i - 1][0] + a[i][0];
  }
  for (i = 1; i <= n; i++)
    for (j = 0; j <= sum[i]; j++) {
      if (j - a[i][1] >= 0 && j <= sum2[n] - sum2[i] + f[i - 1][j - a[i][1]])
        f[i][j] = min(f[i][j], f[i - 1][j - a[i][1]]);
      f[i][j] = min(f[i][j], f[i - 1][j] + a[i][0]);
    }
  for (i = 0; i <= sum[n]; i++)
    if (i <= f[n][i]) ans = min(ans, f[n][i]);
  cout << ans;
  return 0;
}
