#include <bits/stdc++.h>
using namespace std;
struct node {
  int a;
  int b;
} a[100], b[100];
bool cmp(node x, node y) { return (x.b < y.b); }
int n, ans = 1e9 + 7, w, maxa, maxb, a_, b_, x, y;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x == 2) {
      a[a_++].b = y;
      a[a_].a = x;
      maxa += y;
    } else {
      b[b_++].b = y;
      b[b_].a = x;
      maxb += y;
    }
  }
  sort(b, b + b_, cmp);
  sort(a, a + a_, cmp);
  int tmpp = maxa;
  a[a_].b = 0;
  b[b_].b = 0;
  for (int i = a_; i >= 0; i--) {
    tmpp = tmpp - a[i].b;
    int tmp = maxb;
    for (int j = b_; j >= 0; j--) {
      tmp -= b[j].b;
      int cnt = tmpp + tmp;
      if (cnt <= (a_ - i) * 2 + (b_ - j)) {
        ans = min((a_ - i) * 2 + (b_ - j), ans);
      }
    }
  }
  cout << ans << endl;
}
