#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int maxn = 105;
int w1[maxn], w2[maxn];
int sum1[maxn], sum2[maxn];
int main() {
  int n;
  scanf("%d", &n);
  int i, j;
  int what, x;
  int num1 = 1, num2 = 1;
  for (i = 0; i < n; i++) {
    scanf("%d%d", &what, &x);
    if (what == 1)
      w1[num1++] = x;
    else
      w2[num2++] = x;
  }
  sort(w1 + 1, w1 + num1 + 1, greater<int>());
  sort(w2 + 1, w2 + num2 + 1, greater<int>());
  num1--, num2--;
  for (i = 1; i <= num1; i++) {
    sum1[i] = sum1[i - 1] + w1[i];
  }
  for (i = 1; i <= num2; i++) sum2[i] = sum2[i - 1] + w2[i];
  int ans = INT_MAX;
  for (i = 0; i <= num1; i++)
    for (j = 0; j <= num2; j++) {
      if (i + 2 * j >= sum1[num1] + sum2[num2] - sum1[i] - sum2[j]) {
        ans = min(ans, i + 2 * j);
      }
    }
  printf("%d\n", ans);
  return 0;
}
