#include <bits/stdc++.h>
int w[105], t[105], n;
int mem[105][205][205];
int min(int a, int b) {
  if (a > b)
    return b;
  else
    return a;
}
int dfs(int pos, int thi, int whi) {
  if (pos == n) return thi;
  if (mem[pos][thi][whi] != -1) return mem[pos][thi][whi];
  if (thi - t[pos] >= whi + w[pos])
    return mem[pos][thi][whi] = min(dfs(pos + 1, thi - t[pos], whi + w[pos]),
                                    dfs(pos + 1, thi, whi));
  return mem[pos][thi][whi] = dfs(pos + 1, thi, whi);
}
int main() {
  int i, sum;
  while (scanf("%d", &n) != EOF) {
    memset(mem, -1, sizeof(mem));
    sum = 0;
    for (i = 0; i < n; i++) {
      scanf("%d%d", &t[i], &w[i]);
      sum = sum + t[i];
    }
    printf("%d\n", dfs(0, sum, 0));
  }
  return 0;
}
