#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> ichi;
  vector<int> ni;
  for (int i = 0; i < (int)(n); i++) {
    int t, w;
    cin >> t >> w;
    if (t == 1)
      ichi.push_back(w);
    else
      ni.push_back(w);
  }
  sort(ichi.begin(), ichi.end());
  sort(ni.begin(), ni.end());
  int ret = 1 << 30;
  for (int i = 0; i < (int)(ichi.size() + 1); i++)
    for (int j = 0; j < (int)(ni.size() + 1); j++) {
      int w = 0;
      for (int k = 0; k < (int)(i); k++) w += ichi[k];
      for (int k = 0; k < (int)(j); k++) w += ni[k];
      int t = 0;
      for (int k = (int)(i); k < (int)(ichi.size()); k++) t += 1;
      for (int k = (int)(j); k < (int)(ni.size()); k++) t += 2;
      if (t >= w) ret = min(ret, t);
    }
  cout << ret << endl;
  return 0;
}
