#include <bits/stdc++.h>
using namespace std;
int dp[3][303];
int main() {
  int n;
  int x = 0;
  int y = 0;
  cin >> n;
  int num1, num2;
  for (int i = 0; i < n; i++) {
    cin >> num1 >> num2;
    if (num1 == 1)
      dp[1][x++] = num2;
    else
      dp[2][y++] = num2;
  }
  sort(dp[1], dp[1] + x);
  sort(dp[2], dp[2] + y);
  int maxim = INT_MAX;
  for (int i = 0; i <= x; i++) {
    for (int j = 0; j <= y; j++) {
      int sum = 0;
      for (int k = 0; k < x - i; k++) {
        sum += dp[1][k];
      }
      for (int l = 0; l < y - j; l++) {
        sum += dp[2][l];
      }
      if (i + j * 2 >= sum && maxim > i + j * 2) {
        maxim = i + j * 2;
      }
    }
  }
  cout << maxim << endl;
  return 0;
}
