#include <bits/stdc++.h>
using namespace std;
vector<int> s[10];
int n1, n2;
int ok(int a, int b) {
  int sum = a + b * 2;
  int len = 0;
  for (int i = 0; i < n1 - a; i++) len += s[1][i];
  for (int i = 0; i < n2 - b; i++) len += s[2][i];
  return len <= sum;
}
int main() {
  int a, b, n, m, i, j, ans = 99999999;
  ;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d%d", &a, &b);
    s[a].push_back(b);
  }
  sort(s[1].begin(), s[1].end());
  sort(s[2].begin(), s[2].end());
  n1 = s[1].size();
  n2 = s[2].size();
  for (i = 0; i <= n1; i++)
    for (j = 0; j <= n2; j++) {
      if (ok(i, j)) {
        if (i + j * 2 < ans) ans = i + j * 2;
      }
    }
  printf("%d\n", ans);
}
