#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000000 + 7;
const long long int MOD1 = 998244353;
long long int pwr(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a *= a;
    b >>= 1;
  }
  return res;
}
const long long int sss = pwr(2, 32);
long long int strTo(string s) {
  stringstream tmp(s);
  long long int x = 0;
  tmp >> x;
  return x;
}
string NoTo(long long int n) {
  ostringstream str1;
  str1 << n;
  string ans = str1.str();
  return ans;
}
vector<bool> sieve(4000001, true);
void Sieve() {
  sieve[0] = false;
  sieve[1] = false;
  for (long long int i = 2; i * i <= 4000000; i++) {
    if (sieve[i] == true) {
      for (long long int j = i * i; j <= 4000000; j += i) sieve[j] = false;
    }
  }
}
long long int nCr(long long int n, long long int r) {
  long long int ans = 1;
  for (long long int i = (long long int)0; i < (long long int)r; i++) {
    ans = (ans * (n - i));
    ans = (ans / (i + 1));
  }
  return ans;
}
long long int pwrm(long long int a, long long int b, long long int m) {
  a %= m;
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
vector<long long int> adj[300010];
long long int dista[100001];
long long int vis[300010];
long long int par[300001];
long long int cl[100001];
long long int sz = 1;
long long int n, q;
long long int arr[10000001];
void init(long long int n) {
  while (sz < n) sz *= 2;
}
vector<long long int> sum(10000010);
void build(long long int a[], long long int x, long long int l,
           long long int r) {
  if (r - l == 1) {
    sum[x] = a[l];
    return;
  }
  long long int m = (l + r) / 2;
  build(a, 2 * x + 1, l, m);
  build(a, 2 * x + 2, m, r);
  sum[x] = max(sum[2 * x + 1], sum[2 * x + 2]);
}
void buil(long long int a[], long long int x, long long int l,
          long long int r) {
  build(a, x, l, r);
}
long long int suf(long long int l, long long int r, long long int x,
                  long long int lx, long long int rx) {
  if (lx >= r || l >= rx) return 0;
  if (lx >= l && rx <= r) return sum[x];
  long long int m = (lx + rx) / 2;
  return max(suf(l, r, 2 * x + 1, lx, m), suf(l, r, 2 * x + 2, m, rx));
}
long long int su(long long int l, long long int r, long long int x,
                 long long int lx, long long int rx) {
  return suf(l, r, x, lx, rx);
}
long long int ar[1000010];
long long int get(long long int k) {
  long long int sum = 0;
  while (k >= 1) {
    sum = max(ar[k], sum);
    k -= k & -k;
  }
  return sum;
}
void update(long long int in, long long int vl) {
  while (in <= n) {
    ar[in] = max(ar[in], vl);
    in += in & -in;
  }
}
long long int sizee[200010] = {0};
long long int ctr = 0;
void df(long long int sr) {
  vis[sr] = 1;
  long long int ctr = 0;
  for (auto it : adj[sr]) {
    if (!vis[it]) {
      df(it);
      ctr += (1 + sizee[it]);
    }
  }
  sizee[sr] = ctr;
}
long long int fac[2000010];
unsigned long long modInverse(unsigned long long n, int p) {
  return pwrm(n, p - 2, p);
}
long long int level[300001];
void dfs(long long int sr, long long int pr, long long int pa) {
  vis[sr] = 1;
  level[sr] = pr;
  par[sr] = pa;
  for (auto it : adj[sr]) {
    if (!vis[it]) dfs(it, pr + 1, sr);
  }
}
long long int dp[100010];
bool cmp(pair<long long int, long long int> p1,
         pair<long long int, long long int> p2) {
  if (p1.second > p2.second) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int> > v1;
  vector<pair<long long int, long long int> > v2;
  for (long long int i = (long long int)0; i < (long long int)n; i++) {
    long long int x, y;
    cin >> x >> y;
    if (x == 1)
      v1.push_back({x, y});
    else
      v2.push_back({x, y});
  }
  sort(v1.begin(), v1.end(), cmp);
  sort(v2.begin(), v2.end(), cmp);
  long long int mi = 1e18;
  if (v1.empty()) {
    long long int th1 = 0, wd1 = 0;
    for (long long int j = (long long int)0; j < (long long int)v2.size();
         j++) {
      th1 = 0;
      for (long long int k = (long long int)0; k < (long long int)j + 1; k++)
        th1 += v2[k].first;
      wd1 = 0;
      for (long long int k = (long long int)j + 1; k < (long long int)v2.size();
           k++)
        wd1 += v2[k].second;
      if (th1 >= wd1) mi = min(mi, th1);
    }
  } else if (v2.empty()) {
    for (long long int i = (long long int)0; i < (long long int)v1.size();
         i++) {
      long long int th = 0;
      for (long long int j = (long long int)0; j < (long long int)i + 1; j++)
        th += v1[j].first;
      long long int wd = 0;
      for (long long int j = (long long int)i + 1; j < (long long int)v1.size();
           j++)
        wd += v1[j].second;
      if (th >= wd) mi = min(mi, th);
    }
  } else {
    for (long long int i = (long long int)0; i < (long long int)v1.size();
         i++) {
      long long int th = 0;
      for (long long int j = (long long int)0; j < (long long int)i + 1; j++)
        th += v1[j].first;
      long long int wd = 0;
      for (long long int j = (long long int)i + 1; j < (long long int)v1.size();
           j++)
        wd += v1[j].second;
      long long int th1 = th, wd1 = wd;
      for (long long int j = (long long int)0; j < (long long int)v2.size() + 1;
           j++) {
        th1 = th;
        for (long long int k = (long long int)0; k < (long long int)j; k++)
          th1 += v2[k].first;
        wd1 = wd;
        for (long long int k = (long long int)j; k < (long long int)v2.size();
             k++)
          wd1 += v2[k].second;
        if (th1 >= wd1) mi = min(mi, th1);
      }
      if (th1 >= wd1) mi = min(mi, th1);
    }
    for (long long int i = (long long int)0; i < (long long int)v2.size();
         i++) {
      long long int th = 0;
      for (long long int j = (long long int)0; j < (long long int)i + 1; j++)
        th += v2[j].first;
      long long int wd = 0;
      for (long long int j = (long long int)i + 1; j < (long long int)v2.size();
           j++)
        wd += v2[j].second;
      long long int th1 = th, wd1 = wd;
      for (long long int j = (long long int)0; j < (long long int)v1.size() + 1;
           j++) {
        th1 = th;
        for (long long int k = (long long int)0; k < (long long int)j; k++)
          th1 += v1[k].first;
        wd1 = wd;
        for (long long int k = (long long int)j; k < (long long int)v1.size();
             k++)
          wd1 += v1[k].second;
        if (th1 >= wd1) mi = min(mi, th1);
      }
      if (th1 >= wd1) mi = min(mi, th1);
    }
  }
  cout << mi << "\n";
  cerr << "Time Elapsed : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
