#include <bits/stdc++.h>
using namespace std;
vector<int> wts[2];
int sums[2][110];
int main() {
  int N, i, j, t, w, tot, up, min;
  scanf("%d", &N);
  for (i = 0; i < N; ++i) {
    scanf("%d", &t);
    scanf("%d", &w);
    wts[t - 1].push_back(w);
  }
  sort(wts[0].begin(), wts[0].end());
  sort(wts[1].begin(), wts[1].end());
  min = 1000000000;
  sums[0][0] = sums[1][0] = 0;
  for (i = 1; i <= wts[0].size(); ++i)
    sums[0][i] = sums[0][i - 1] + wts[0][i - 1];
  for (i = 1; i <= wts[1].size(); ++i)
    sums[1][i] = sums[1][i - 1] + wts[1][i - 1];
  for (i = 0; i <= wts[0].size(); ++i) {
    for (j = 0; j <= wts[1].size(); ++j) {
      tot = i + (2 * j);
      up = sums[0][wts[0].size() - i] + sums[1][wts[1].size() - j];
      if (up <= tot && tot < min) min = tot;
    }
  }
  printf("%d\n", min);
  return 0;
}
