import java.io.FileNotFoundException; import java.math.BigInteger; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException { new Main().run(); } void run() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[][] ok = new int[N + 1][100000 + 1]; for (int i = 0; i < ok.length; ++i) { for (int j = 0; j < ok[i].length; ++j) { ok[i][j] = Integer.MAX_VALUE / 3; } } ok[0][0] = 0; for (int i = 0; i < N; ++i) { int A = sc.nextInt(); int B = sc.nextInt(); for (int j = 0; j < ok[i].length; ++j) { if (ok[i][j] == Integer.MAX_VALUE / 3) continue; ok[i + 1][j + A] = Math.min(ok[i + 1][j + A], ok[i][j]); ok[i + 1][j] = Math.min(ok[i + 1][j], ok[i][j] + B); } } int ans = Integer.MAX_VALUE / 3; for (int i = 0; i < ok[N].length; ++i) { ans = Math.min(ans, Math.max(i, ok[N][i])); } System.out.println(ans); } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }