#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[105];
int dp[105][205];
bool can[500];
int sum;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int t, w;
    cin >> t >> w;
    sum += w;
    a[i] = {t, w};
  }
  can[0] = true;
  for (int i = 1; i <= n; i++) {
    for (int j = 300; j >= 0; j--) {
      if (can[j]) can[j + a[i].first] = true;
    }
  }
  for (int i = 1; i <= 200; i++) {
    for (int j = 1; j <= n; j++) {
      dp[j][i] = dp[j - 1][i];
      if (a[j].first > i) continue;
      dp[j][i] = max(dp[j - 1][i], dp[j - 1][i - a[j].first] + a[j].second);
    }
  }
  for (int i = 1; i <= 200; i++) {
    if (dp[n][i] + i >= sum && can[i]) {
      cout << i;
      break;
    }
  }
  return 0;
}
