#include <bits/stdc++.h>
using namespace std;
int dp[10005], t[1005], w[1005], n, i, j, ans, sum = 0;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> t[i] >> w[i];
    sum += t[i];
  }
  for (i = 1; i <= sum; i++) dp[i] = 1 << 30;
  for (i = 1; i <= n; i++)
    for (j = sum; j >= t[i]; j--) dp[j] = min(dp[j], dp[j - t[i]] + w[i]);
  for (i = sum; i >= 0; i--) {
    if (sum - i >= dp[i]) {
      ans = sum - i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
