#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[100], b[100];
  int a1 = 0, b1 = 0;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int c, d;
    scanf("%d%d", &c, &d);
    if (c == 1)
      a[a1++] = d;
    else
      b[b1++] = d;
    sum += c;
  }
  sort(a, a + a1);
  sort(b, b + b1);
  int sumA[101] = {0};
  int sumB[101] = {0};
  for (int i = 1; i <= a1; i++) sumA[i] = sumA[i - 1] + a[i - 1];
  for (int i = 1; i <= b1; i++) sumB[i] = sumB[i - 1] + b[i - 1];
  int tot = 1e9;
  for (int i = 0; i <= a1; i++)
    for (int j = 0; j <= b1; j++) {
      if (sum - (i + 2 * j) >= sumA[i] + sumB[j])
        tot = min(tot, sum - (i + 2 * j));
    }
  printf("%d\n", tot);
}
