#include <bits/stdc++.h>
using namespace std;
int w[2][105], sz[2];
int main() {
  ios_base::sync_with_stdio(0);
  cin.clear();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    w[x][sz[x]++] = y;
  }
  sort(w[0], w[0] + sz[0]);
  sort(w[1], w[1] + sz[1]);
  int mn = 1000000000;
  for (int i = sz[0]; i >= 0; i--) {
    for (int j = sz[1]; j >= 0; j--) {
      int tot = 0;
      for (int k = 0; k < i; k++) tot += w[0][k];
      for (int k = 0; k < j; k++) tot += w[1][k];
      int len = (sz[0] - i) + (sz[1] - j) * 2;
      if (tot <= len) mn = min(mn, len);
    }
  }
  cout << mn;
  return 0;
}
