#include <bits/stdc++.h>
using namespace std;
const int INF = 0X3F3F3F3F;
const double PI = acos(-1.0);
const double EPS = 1e-11;
const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
inline int sgn(double x) { return x < -EPS ? -1 : x > EPS ? 1 : 0; }
inline string tolower(string s) {
  for (int i = 0; i < (int)(s.size()); ++i) s[i] = tolower(s[i]);
  return s;
}
inline string toupper(string s) {
  for (int i = 0; i < (int)(s.size()); ++i) s[i] = toupper(s[i]);
  return s;
}
template <class T>
inline T sqr(const T& x) {
  return x * x;
}
template <class T>
inline int toint(const T& x) {
  stringstream ss;
  ss << x;
  int r;
  ss >> r;
  return r;
}
template <class T>
inline int todouble(const T& x) {
  stringstream ss;
  ss << x;
  double r;
  ss >> r;
  return r;
}
template <class T>
inline string tostr(const T& x) {
  ostringstream os("");
  os << x;
  return os.str();
}
template <class T>
void stov(string s, vector<T>& vi) {
  vi.clear();
  istringstream sin(s);
  for (T v; sin >> v; vi.push_bakc(v))
    ;
}
template <class T>
void vtos(vector<T> vi, string& s) {
  ostringstream sout;
  for (int i = 0; i < vi.size(); i++) {
    if (i > 0) sout << ' ';
    sout << vi[i];
  }
  s = sout.str();
}
const int MAXN = 1011;
string s;
int n, t[MAXN], w[MAXN];
pair<int, int> p[MAXN];
bool dp[111][222][222];
int sum;
bool check(int mid) {
  memset(dp, 0, sizeof(dp));
  dp[0][0][0] = 1;
  int len = 0;
  for (int i = 1; i <= n; i++) {
    len += t[i];
    for (int j = 0; j <= len; j++) {
      for (int k = 0; k <= sum; k++) {
        if (j >= t[i]) dp[i][j][k] |= dp[i - 1][j - t[i]][k];
        if (k + w[i] <= sum) {
          dp[i][j][k + w[i]] |= dp[i - 1][j][k];
        }
      }
    }
  }
  for (int i = 0; i <= mid; i++) {
    if (dp[n][mid][i]) return true;
  }
  return false;
}
int main() {
  while (scanf("%d", &n) != EOF) {
    sum = 0;
    for (int i = int(1); i < int(n + 1); i++) {
      scanf("%d%d", &t[i], &w[i]);
      p[i].first = t[i];
      p[i].second = w[i];
      sum += t[i];
    }
    sort(p, p + n);
    int l = 1, r = sum;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (check(mid)) {
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    printf("%d\n", l);
  }
}
