#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int t = 0;
  vector<int> v, v1;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    t += a;
    if (a == 1)
      v.push_back(a + b);
    else
      v1.push_back(a + b);
  }
  v1.push_back(0);
  sort(v.begin(), v.end());
  sort(v1.begin(), v1.end());
  for (int i = 1; i < v1.size(); i++) v1[i] += v1[i - 1];
  int maxi = 0;
  for (int i = 0; i < v1.size(); i++) {
    if (v1[i] > t) break;
    int z = t - v1[i];
    int j = 0;
    while (j < v.size()) {
      if (v[j] > z) break;
      z -= v[j];
      j++;
    }
    maxi = max(2 * (i) + j, maxi);
  }
  cout << t - maxi;
  return 0;
}
