#include <bits/stdc++.h>
using namespace std;
int dp[201], x[101], y[101];
int main() {
  int i, j, n, s = 0;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> x[i] >> y[i], s += x[i];
  for (i = 1; i <= n; i++)
    for (j = s; j >= x[i] + y[i]; j--)
      dp[j] = max(dp[j], dp[j - x[i] - y[i]] + x[i]);
  cout << s - dp[s] << endl;
}
