#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, v[N], w[N], sum, f[N << 1];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &v[i], &w[i]), sum += v[i];
  for (int i = 1; i <= sum; i++) f[i] = 0x3f3f3f3f;
  for (int i = 1; i <= n; i++)
    for (int j = sum; j >= v[i]; j--) f[j] = min(f[j], f[j - v[i]] + w[i]);
  for (int i = sum; i >= 0; i--) {
    if (sum - i >= f[i]) {
      printf("%d\n", sum - i);
      return 0;
    }
  }
  return 0;
}
