import java.io.*; import java.util.*; public class Main { static int[] marks; static int[] books; static int[][] dp; static int n; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); n = sc.nextInt(); marks = new int[n]; books = new int[n]; for (int i = 0; i < n; i++) { marks[i] = sc.nextInt(); books[i] = sc.nextInt(); } dp = new int[1 << n][n]; int ans = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { ans = Math.min(ans, dfw((1 << n) - 1, i)); } System.out.println(ans); } static int dfw(int mask, int idx) { if (getPop(mask) == 1) { return 0; } if (dp[mask][idx] == 0) { dp[mask][idx] = Integer.MAX_VALUE / 2; for (int i = 0; i < n; i++) { if (i == idx || (mask & (1 << i)) == 0) { continue; } dp[mask][idx] = Math.min(dp[mask][idx], Math.max(dfw(mask ^ (1 << idx), i), books[i] - marks[i] + marks[idx])); } } return dp[mask][idx]; } static int getPop(int x) { int pop = 0; while (x > 0) { pop += x % 2; x >>= 1; } return pop; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }