#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
void solve() {
  long long n;
  cin >> n;
  std::vector<long long> v1, v2;
  for (long long i = 0; i < n; i++) {
    long long l, w;
    cin >> l >> w;
    if (l == 1)
      v1.push_back(w);
    else
      v2.push_back(w);
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  long long ans = INT_MAX;
  long long l2 = 0;
  for (long long i = 0; i <= v1.size(); i++) {
    if (i != 0) l2 += v1[i - 1];
    long long l3 = l2;
    for (long long j = 0; j <= v2.size(); j++) {
      long long l1 = v1.size() - i + 2 * (v2.size() - j);
      if (j != 0) l3 += v2[j - 1];
      if (l3 <= l1) ans = min(ans, l1);
    }
  }
  cout << ans << endl;
}
signed main() {
  long long t = 1;
  while (t--) {
    solve();
  }
}
