#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int dp[300030][20]; int d[20][20]; int a[20], b[20]; int main() { int n; cin >> n; for (int i = 0; i < (1 << n); i++) { for (int j = 0; j < n; j++) { dp[i][j] = 1000000007; } } for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; b[i] -= a[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) { d[i][j] = 0; } else { d[i][j] = b[i] + a[j]; } } } for (int i = 0; i < n; i++) { dp[(1 << i)][i] = 0; } for (int i = 0; i < (1 << n); i++) { for (int v = 0; v < n; v++) { if (!(i & (1 << v))) { continue; } for (int u = 0; u < n; u++) { if (i & (1 << u)) { continue; } dp[i | (1 << u)][u] = min(dp[i | (1 << u)][u], max(dp[i][v], d[v][u])); } } } int ans = 1000000007; for (int i = 0; i < n; i++) { if (ans > dp[(1 << n) - 1][i]) { ans = dp[(1 << n) - 1][i]; } } cout << ans << endl; }