#include <bits/stdc++.h>
using namespace std;
const int MAXC = (int)1e9;
vector<int> a, b;
int n, na, nb, sumWidth;
bool myCmp(int a, int b) { return (a > b); }
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);
    if (t == 1)
      a.push_back(w);
    else
      b.push_back(w);
    sumWidth += w;
  }
  na = (int)a.size();
  nb = (int)b.size();
  sort(a.begin(), a.end(), myCmp);
  sort(b.begin(), b.end(), myCmp);
  int res = MAXC;
  for (int i = 0; i <= na; i++)
    for (int j = 0; j <= nb; j++) {
      int thick = i + 2 * j, width = 0;
      for (int k = 0; k < i; k++) width += a[k];
      for (int k = 0; k < j; k++) width += b[k];
      if (sumWidth - width <= thick) res = min(res, thick);
    }
  printf("%d\n", res);
}
