#include <bits/stdc++.h>
using namespace std;
int i, j, N1, lung;
int result = 1 << 30, bb, aa, n, t;
vector<int> h[3];
int main() {
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> aa >> bb;
    h[aa].push_back(bb);
  }
  int N1 = h[1].size();
  int N2 = h[2].size();
  sort(h[1].begin(), h[1].end());
  sort(h[2].begin(), h[2].end());
  for (i = -1; i < N1; ++i)
    for (j = -1; j < N2; ++j) {
      lung = 0;
      for (t = N1 - i - 2; t >= 0; --t) lung += h[1][t];
      for (t = N2 - j - 2; t >= 0; --t) lung += h[2][t];
      if (i + (j + 1) * 2 + 1 >= lung)
        result = min(result, i + 1 + (j + 1) * 2);
    }
  cout << result;
  return 0;
}
