#include <bits/stdc++.h>
using namespace std;
int t[110], w[110];
int dp[210];
int n;
int main() {
  int total = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> t[i] >> w[i], total += w[i];
  memset(dp, -1, sizeof(dp));
  dp[0] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 200; j >= 1; j--)
      if (j - t[i] >= 0 && dp[j - t[i]] != -1)
        dp[j] = max(dp[j], dp[j - t[i]] + w[i]);
  for (int j = 1; j <= 200; j++)
    if (dp[j] != -1 && j >= total - dp[j]) {
      printf("%d\n", j);
      return 0;
    }
}
