#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
vector<int> a, b;
int n, sumWidth;
bool myCmp(int a, int b) { return (a > b); }
bool construct(int sumThick) {
  int thick = 0, i = 0, j = 0, width = 0;
  while (thick < sumThick && (i < (int)a.size() || j < (int)b.size())) {
    if (i == (int)a.size()) {
      thick += 2;
      width += b[j];
      j++;
    } else if (j == (int)b.size()) {
      thick++;
      width += a[i];
      i++;
    } else if (a[i] >= b[j]) {
      thick++;
      width += a[i];
      i++;
    } else if (i < (int)a.size() - 1 && a[i] + a[i + 1] >= b[j]) {
      thick += 2;
      width += a[i] + a[i + 1];
      i += 2;
    } else {
      thick += 2;
      width += b[j];
      j++;
    }
  }
  if (sumThick == thick) return sumWidth - width <= thick;
  int width1 = 0, width2 = 0;
  if (i) width1 = width - a[i - 1];
  if (i < (int)a.size()) width2 = width - b[j - 1] + a[i];
  width = max(width1, width2);
  return sumWidth - width <= sumThick;
}
int main() {
  if (0) {
    freopen("a.inp", "r", stdin);
    freopen("a.out", "w", stdout);
  };
  scanf("%d", &n);
  int t, w;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &t, &w);
    sumWidth += w;
    if (t == 1)
      a.push_back(w);
    else
      b.push_back(w);
  }
  sort(a.begin(), a.end(), myCmp);
  sort(b.begin(), b.end(), myCmp);
  for (int thick = 1; thick <= 200; thick++)
    if (construct(thick)) {
      printf("%d\n", thick);
      return 0;
    }
}
