#include <bits/stdc++.h>
using namespace std;
int n, dp[100005], maxn, w[100005], t[100005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &t[i], &w[i]), maxn += t[i];
  for (int i = 1; i <= maxn; i++) dp[i] = 1e9;
  for (int i = 1; i <= n; i++)
    for (int j = maxn; j >= t[i]; j--) dp[j] = min(dp[j], dp[j - t[i]] + w[i]);
  for (int i = maxn; i >= 0; i--)
    if (maxn - i >= dp[i]) {
      printf("%d", maxn - i);
      break;
    }
  return 0;
}
