#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t, w, i;
  cin >> n;
  int a[n + 1];
  int b[n + 1];
  int size1 = 0;
  int size2 = 0;
  for (i = 1; i <= n; i++) {
    cin >> t >> w;
    if (t == 1) {
      size1++;
      a[size1] = w;
    } else {
      size2++;
      b[size2] = w;
    }
  }
  sort(a + 1, a + size1 + 1);
  sort(b + 1, b + size2 + 1);
  int thick;
  int min = 1e5;
  for (i = 0; i <= size2; i++) {
    int sum;
    thick = 2 * i;
    for (int j = 0; j <= size1; j++) {
      int x;
      sum = 0;
      x = thick + j;
      for (int k = 1; k <= size1 - j; k++) sum += a[k];
      for (int k = 1; k <= size2 - i; k++) sum += b[k];
      if (sum > x)
        continue;
      else {
        if (x < min) min = x;
      }
    }
  }
  cout << min << endl;
  return 0;
}
