#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> One, Two;
  for (int i = 0; i < n; i++) {
    int t, w;
    cin >> t >> w;
    if (t == 1)
      One.push_back(w);
    else
      Two.push_back(w);
  }
  sort(One.begin(), One.end());
  sort(Two.begin(), Two.end());
  int N = One.size(), M = Two.size();
  int ans = 1000000000;
  for (int i = 0; i <= N; i++)
    for (int j = 0; j <= M; j++) {
      int w = i + 2 * j;
      int v = 0;
      for (int k = 0; k < N - i; k++) v += One[k];
      for (int k = 0; k < M - j; k++) v += Two[k];
      if (v <= w) ans = min(ans, w);
    }
  cout << ans << endl;
  return 0;
}
