#include <bits/stdc++.h>
using namespace std;
int n;
int dp[101][300][300];
pair<int, int> yo[101];
int ck(int pos, int ans, int bro) {
  if (pos == n) return 0;
  if (dp[pos][ans][bro]) return dp[pos][ans][bro];
  int takla2 = 0, takla1 = 0;
  if (ans - yo[pos].second >= bro + yo[pos].first)
    takla1 =
        yo[pos].second + ck(pos + 1, ans - yo[pos].second, bro + yo[pos].first);
  takla2 = ck(pos + 1, ans, bro);
  if (takla1 > takla2)
    dp[pos][ans][bro] = takla1;
  else
    dp[pos][ans][bro] = takla2;
  return dp[pos][ans][bro];
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> yo[i].second >> yo[i].first;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < n - i; j++) {
      if (yo[j].first < yo[j - 1].first) {
        swap(yo[j], yo[j - 1]);
      } else if (yo[j].first == yo[j - 1].first) {
        if (yo[j].second > yo[j - 1].second) {
          swap(yo[j], yo[j - 1]);
        }
      }
    }
  }
  int ans = 0, res;
  for (int i = 0; i < n; i++) ans += yo[i].second;
  res = ck(0, ans, 0);
  cout << ans - res;
  return 0;
}
