#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, t, w, j, mini;
  vector<int> W1, W2;
  mini = 100000000;
  cin >> n;
  W1.push_back(0);
  W2.push_back(0);
  for (i = 0; i < n; i++) {
    cin >> t >> w;
    if (t == 1)
      W1.push_back(w);
    else
      W2.push_back(w);
  }
  sort(W1.begin(), W1.end());
  sort(W2.begin(), W2.end());
  for (i = 1; i < W1.size(); i++) W1[i] += W1[i - 1];
  for (i = 1; i < W2.size(); i++) W2[i] += W2[i - 1];
  int s1, s2;
  s1 = W1.size() - 1;
  s2 = W2.size() - 1;
  for (i = 0; i < W1.size(); i++) {
    for (j = 0; j < W2.size(); j++) {
      if ((s1 - i) + 2 * (s2 - j) >= W1[i] + W2[j])
        mini = min(mini, (s1 - i) + 2 * (s2 - j));
    }
  }
  cout << mini << endl;
  return 0;
}
