#include <bits/stdc++.h>
using namespace std;
int INF = 0;
int N;
int to;
struct book {
  int w;
  int t;
};
vector<book> shelf;
int mem[105][205][205];
int go(int idx, int ti, int wei) {
  int res = INF;
  if (idx == N) {
    if (ti >= wei) {
      return 0;
    } else
      return res;
  }
  if (wei > 200) return res;
  if (mem[idx][ti][wei] > -1) return mem[idx][ti][wei];
  res = min(res, go(idx + 1, ti + shelf[idx].t, wei) + shelf[idx].t);
  res = min(res, go(idx + 1, ti, wei + shelf[idx].w));
  mem[idx][ti][wei] = res;
  return res;
};
int main() {
  ios_base::sync_with_stdio(false);
  memset(mem, -1, sizeof mem);
  cin >> N;
  book a;
  for (int i = 0; i < N; ++i) {
    cin >> a.t >> a.w;
    to += a.w;
    INF += a.t;
    shelf.push_back(a);
  }
  int res = go(0, 0, 0);
  cout << res << endl;
  return 0;
}
