#include <bits/stdc++.h>
using namespace std;
int a[109], b[109], suma[109], sumb[109];
int main() {
  int n, ones = 1, twos = 1, tot = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    tot += x;
    if (x == 1)
      a[ones++] = y;
    else
      b[twos++] = y;
  }
  suma[0] = 0, sumb[0] = 0;
  sort(a + 1, a + ones);
  for (int i = 1; i < ones; i++) suma[i] = suma[i - 1] + a[i];
  sort(b + 1, b + twos);
  for (int i = 1; i < twos; i++) sumb[i] = sumb[i - 1] + b[i];
  int ans = 0x7fffffff;
  for (int i = 0; i < ones; i++)
    for (int j = 0; j < twos; j++) {
      if (suma[i] + sumb[j] <= tot - (i + 2 * j))
        ans = min(ans, tot - (i + 2 * j));
    }
  cout << ans << endl;
  return 0;
}
