#include <bits/stdc++.h>
using namespace std;
long long a[105], b[105];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long one = 0;
  long long two = 0;
  for (long long i = 0; i < n; ++i) {
    long long t, w;
    cin >> t >> w;
    if (t == 1) {
      a[one] = w;
      one++;
    } else {
      b[two] = w;
      two++;
    }
  }
  sort(a, a + one);
  sort(b, b + two);
  long long ans = 1e6;
  for (long long i = 0; i <= one; ++i) {
    for (long long j = 0; j <= two; ++j) {
      long long s = 0;
      for (long long k = 0; k < one - i; ++k) s += a[k];
      for (long long r = 0; r < two - j; ++r) s += b[r];
      if ((i + 2 * j) >= s && ans > (i + 2 * j)) ans = i + 2 * j;
    }
  }
  cout << ans << "\n";
}
