import java.util.*; public class Main { static int[] arrA; static int[] arrB; static int[][] dp; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); arrA = new int[n]; arrB = new int[n]; int sumA = 0; int sumB = 0; for (int i = 0; i < n; i++) { arrA[i] = sc.nextInt(); sumA += arrA[i]; arrB[i] = sc.nextInt(); sumB += arrB[i]; } dp = new int[n][sumA + 1]; for (int[] arr : dp) { Arrays.fill(arr, -1); } int min = Integer.MAX_VALUE; for (int i = 0; i <= sumA; i++) { min = Math.min(min, Math.max(i, sumB - dfw(n - 1, i))); } System.out.println(min); } static int dfw(int idx, int time) { if (time < 0) { return Integer.MIN_VALUE; } if (idx < 0) { return 0; } if (dp[idx][time] == -1) { dp[idx][time] = Math.max(dfw(idx - 1, time), dfw(idx - 1, time - arrA[idx]) + arrB[idx]); } return dp[idx][time]; } }