#include <bits/stdc++.h>
using namespace std;
int n, s = 0;
vector<int> u, d;
void solve() {
  int ans = s;
  for (int i = 0; i <= u.size(); ++i) {
    for (int j = 0; j <= d.size(); ++j) {
      int q = 0, p = i + j * 2;
      for (int k = 0; k < i; ++k) {
        q += u[k];
      }
      for (int k = 0; k < j; ++k) {
        q += d[k];
      }
      if (s - p >= q) {
        ans = min(ans, s - p);
      }
    }
  }
  printf("%d", ans);
}
int main(int argc, char *argv[]) {
  scanf("%d", &n);
  while (n--) {
    int t, w;
    scanf("%d%d", &t, &w);
    if (t == 1) {
      u.push_back(w);
    } else {
      d.push_back(w);
    }
    s += t;
  }
  sort(u.begin(), u.end());
  sort(d.begin(), d.end());
  solve();
  return 0;
}
