#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream& operator<<(ostream& out, const pair<A, B>& p) {
  out << "(" << p.first << "," << p.second << ") ";
  return out;
}
template <typename A, typename B>
void printP(const pair<A, B>& p, const char* str = NULL) {
  if (!(1 && !1)) return;
  if (str != NULL) cout << str << ":";
  cout << "(" << p.first << "," << p.second << ") ";
}
template <typename T>
void printV(const vector<T>& v, const char* str = NULL) {
  if (!(1 && !1)) return;
  if (str != NULL) cout << str << ": ";
  for (int i = 0; i < (v.size()); ++i) cout << v[i] << " ";
  cout << endl;
}
template <typename T>
void printC(T& container, const char* str = NULL) {
  if (!(1 && !1)) return;
  if (str != NULL) cout << str << ":";
  for (__typeof((container).begin()) it = ((container).begin());
       it != (container).end(); ++it) {
    cout << (*it) << " ";
  }
  cout << endl;
}
const int INF = 1000010111;
const int S_N = 152;
const int MOD = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<int> t1, t2;
  for (int i = 0; i < n; i++) {
    int thick, width;
    cin >> thick >> width;
    ((thick == 1) ? t1 : t2).push_back(width);
  }
  sort(t1.begin(), t1.end(), greater<int>());
  sort(t2.begin(), t2.end(), greater<int>());
  int mini = INF;
  for (int c1 = 0; c1 <= t1.size(); c1++) {
    for (int c2 = 0; c2 <= t2.size(); c2++) {
      int tSum = 1 * c1 + 2 * c2;
      int wSum = 0;
      for (int i = c1; i < t1.size(); i++) wSum += t1[i];
      for (int i = c2; i < t2.size(); i++) wSum += t2[i];
      if (tSum >= wSum) mini = min(mini, tSum);
    }
  }
  cout << mini << endl;
  return 0;
}
