#include <bits/stdc++.h>
using namespace std;
long long n, k, ans = 34343434;
vector<long long> a;
vector<long long> b;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    if (x == 1)
      a.push_back(y);
    else
      b.push_back(y);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (int v = 0; v <= a.size(); v++) {
    for (int u = 0; u <= b.size(); u++) {
      long long width = v + u * 2, len = 0;
      for (int i = 0; i < a.size() - v; i++) len += a[i];
      for (int i = 0; i < b.size() - u; i++) len += b[i];
      if (width >= len) ans = min(ans, width);
    }
  }
  cout << ans << endl;
  return 0;
}
