#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a, b;
  for (int i = 0; i < n; ++i) {
    int t, w;
    cin >> t >> w;
    if (t == 1)
      a.push_back(w);
    else
      b.push_back(w);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  int odp = INF;
  for (int i = 0; i <= a.size(); ++i) {
    for (int j = 0; j <= b.size(); ++j) {
      int r = 0;
      for (int k = i; k < a.size(); ++k) r += a[k];
      for (int k = j; k < b.size(); ++k) r += b[k];
      if (r <= i + 2 * j) odp = min(odp, i + 2 * j);
    }
  }
  cout << odp;
  return 0;
}
