#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
} a[105], b[105];
int sum1[105], sum2[105];
bool cmp(struct node a, struct node b) { return a.y > b.y; }
int main() {
  int n;
  int count1 = 0, count2 = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (x == 1) {
      count1++;
      a[count1].x = x;
      a[count1].y = y;
    } else {
      count2++;
      b[count2].x = x;
      b[count2].y = y;
    }
  }
  sort(a + 1, a + count1 + 1, cmp);
  sort(b + 1, b + count2 + 1, cmp);
  for (int i = 1; i <= count1; i++) sum1[i] = sum1[i - 1] + a[i].y;
  for (int i = 1; i <= count2; i++) sum2[i] = sum2[i - 1] + b[i].y;
  int ans = 1000000;
  for (int i = 0; i <= count1; i++)
    for (int j = 0; j <= count2; j++) {
      int thi = i + 2 * j, w = sum1[count1] - sum1[i] + sum2[count2] - sum2[j];
      if (w <= thi) ans = min(ans, thi);
    }
  printf("%d\n", ans);
  return 0;
}
