import java.io.*; import java.util.*; public class Main_yukicoder771 { private static Scanner sc; private static Printer pr; private static void solve() { final long INF = Long.MAX_VALUE; int n = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); b[i] = sc.nextInt(); } int m = 0x1 << n; long[][] dp = new long[n][m]; for (int i = 0; i < n; i++) { Arrays.fill(dp[i], INF); dp[i][0x1 << i] = 0; } for (int i = 1; i < m; i++) { for (int j = 0; j < n; j++) { if ((i & 0x1 << j) == 0) { continue; } int d1 = b[j] - a[j]; for (int k = 0; k < n; k++) { if ((i & 0x1 << k) != 0) { continue; } int d2 = a[k]; dp[k][i | 0x1 << k] = Math.min(dp[k][i | 0x1 << k], Math.max(d1 + d2, dp[j][i])); } } } long min = INF; for (int i = 0; i < n; i++) { // pr.println(Arrays.toString(dp[i])); min = Math.min(min, dp[i][m - 1]); } pr.println(min); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } static class Printer extends PrintWriter { Printer(OutputStream out) { super(out); } } }