#include <bits/stdc++.h>
using namespace std;
const long long N = 5005;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<long long> width[2];
  for (long long i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    width[x - 1].push_back(y);
  }
  width[0].push_back(0);
  width[1].push_back(0);
  sort(width[0].begin(), width[0].end());
  sort(width[1].begin(), width[1].end());
  for (long long i = 0; i < 2; i++) {
    for (long long j = 1; j < width[i].size(); j++)
      width[i][j] += width[i][j - 1];
  }
  long long a = width[0].size();
  long long b = width[1].size();
  long long minsofar = 1e12;
  for (long long i = 0; i < a; i++) {
    for (long long j = 0; j < b; j++) {
      long long x = i * 1 + j * 2;
      long long y = width[0][a - 1 - i] + width[1][b - j - 1];
      if (y > x) continue;
      minsofar = min(minsofar, x);
    }
  }
  cout << minsofar;
  return 0;
}
