import java.util.*; import java.io.*; public class Main { static int[] befores; static int[] afters; static int[][] dp; static int n; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(br.readLine()); befores = new int[n]; afters = new int[n]; for (int i = 0; i < n; i++) { String[] line = br.readLine().split(" ", 2); befores[i] = Integer.parseInt(line[0]); afters[i] = Integer.parseInt(line[1]) - befores[i]; } dp = new int[n + 1][(int)(Math.pow(2, n))]; int min = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { min = Math.min(min, dfw(i, (int)(Math.pow(2, n) - 1))); } System.out.println(min); } static int dfw(int idx, int key) { if (key == (int)(Math.pow(2, idx))) { return 0; } if (dp[idx][key] != 0) { return dp[idx][key]; } int min = Integer.MAX_VALUE; int next = key ^ (int)(Math.pow(2, idx)); for (int i = 0; i < n; i++) { int x = (int)(Math.pow(2, i)); if ((next & x) == 0) { continue; } min = Math.min(min, Math.max(dfw(i, next), afters[i] + befores[idx])); } dp[idx][key] = min; return min; } }