#include <bits/stdc++.h>
using namespace std;
const long long MaxN = 1e7 + 5;
const long long modnum = 998244353;
const int inf = 0x3f3f3f3f;
int main() {
  int n;
  scanf("%d", &n);
  int f[205] = {0};
  int w[105], v[105], s[105] = {0};
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &w[i], &v[i]);
    s[i] = s[i - 1] + w[i];
  }
  for (int i = 1; i <= s[n]; i++) {
    f[i] = inf;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = s[n]; j >= w[i]; j--) {
      f[j] = min(f[j], f[j - w[i]] + v[i]);
    }
  }
  for (int i = s[n]; i >= 0; i--) {
    if (s[n] - i >= f[i]) {
      printf("%d\n", s[n] - i);
      break;
    }
  }
  return 0;
}
