#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; ll N; vector a, b; ll full; vector> dp; ll dfs(ll S, ll last) { if (last == -1) { ll res = INF; for (ll i = 0; i < N; i++) { chmin(res, dfs(S | (1 << i), i)); } return res; } if (S == full) { return 0; } if (dp[S][last] != -1) return dp[S][last]; ll res = INF; for (ll i = 0; i < N; i++) { if (!(S >> i & 1)) { chmin(res, max(dfs(S | (1 << i), i) , b[last] - a[last] + a[i])); } } return dp[S][last] = res; } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ scanf("%lld", &N); a.resize(N), b.resize(N); for (ll i = 0; i < N; i++) scanf("%lld %lld", &a[i], &b[i]); full = (1 << N) - 1; dp = vector>(full, vector(N, -1)); cout << dfs(0, -1) << endl; return 0; }