#include <bits/stdc++.h>
using namespace std;
struct Book {
  int t;
  long long w;
};
Book b[101];
bool cmp1(Book a, Book b) {
  if (a.w > b.w)
    return 1;
  else
    return 0;
}
bool cmp2(Book a, Book b) {
  if (a.t < b.t)
    return 1;
  else
    return 0;
}
bool cmp3(long long a, long long b) {
  if (a > b)
    return 1;
  else
    return 0;
}
long long dp[210];
bool solve[210];
int main() {
  int n;
  while (cin >> n) {
    long long v1[101], v2[101];
    int cnt1 = 0, cnt2 = 0;
    int sumt = 0;
    for (int i = 0; i < n; i++) {
      cin >> b[i].t >> b[i].w;
      sumt += b[i].t;
      if (b[i].t == 1)
        v1[cnt1++] = b[i].w;
      else
        v2[cnt2++] = b[i].w;
    }
    sort(v1, v1 + cnt1, cmp3);
    sort(v2, v2 + cnt2, cmp3);
    memset(dp, 0, sizeof(dp));
    memset(solve, false, sizeof(solve));
    long long s1[101], s2[101];
    s1[1] = v1[0];
    s2[1] = v2[0];
    s1[0] = 0;
    s2[0] = 0;
    for (int i = 2; i <= cnt1; i++) {
      s1[i] = s1[i - 1] + v1[i - 1];
    }
    for (int i = 2; i <= cnt2; i++) {
      s2[i] = s2[i - 1] + v2[i - 1];
    }
    for (int i = 0; i <= cnt1; i++) {
      for (int j = 0; j <= cnt2; j++) {
        int s = i;
        int t = j;
        if (!solve[s + t * 2] ||
            dp[s + t * 2] > ((s1[cnt1] - s1[s]) + (s2[cnt2] - s2[t]))) {
          dp[s + t * 2] = (s1[cnt1] - s1[s]) + (s2[cnt2] - s2[t]);
          solve[s + t * 2] = true;
        }
      }
    }
    int ans = -1;
    for (int i = 1; i <= sumt; i++) {
      if (dp[i] <= i && solve[i]) {
        ans = i;
        break;
      }
    }
    if (ans == -1) ans = sumt;
    cout << ans << endl;
  }
}
