#include using namespace std; typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for(int i = (l) ; i < (r); i++) #define incII(i, l, r) for(int i = (l) ; i <= (r); i++) #define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--) #define decII(i, l, r) for(int i = (r) ; i >= (l); i--) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define PQ priority_queue #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define FOR(it, v) for(auto it = v.begin(); it != v.end(); ++it) #define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it) template bool setmin(T & a, T b) { if(b < a) { a = b; return true; } else { return false; } } template bool setmax(T & a, T b) { if(b > a) { a = b; return true; } else { return false; } } template bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } } template bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } } template T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template T lcm(T a, T b) { return a / gcd(a, b) * b; } // ---- ---- #define bit(b, i) (((b) >> (i)) & 1) int n, a[20], b[20], INF = 1e5; vector> g[20]; int main() { cin >> n; inc1(i, n) { cin >> a[i] >> b[i]; b[i] -= a[i]; } b[ 0] = -INF; a[n + 1] = -INF; n += 2; inc(i, n) { inc(j, n) { if(i == j) { continue; } g[i].EB(j, b[i] + a[j]); } } vector> dp(1 << n, vector(n, INF)); dp[1][0] = 0; inc(b, 1 << n) { inc(i, n) { for(auto && e: g[i]) { if(bit(b, e.FI)) { continue; } setmin(dp[b | (1 << e.FI)][e.FI], max(dp[b][i], e.SE)); } } } cout << dp.back()[n - 1] << endl; return 0; }