#include using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; b[i] -= a[i]; } const int INF = 100000; vector< vector > dp(1 << n, vector(n, INF)); for (int i = 0; i < n; i++) dp[1 << i][i] = 0; for (int i = 0; i + 1 < (1 << n); i++) { for (int j = 0; j < n; j++) { if (!(i & (1 << j))) continue; for (int k = 0; k < n; k++) { if (i & (1 << k)) continue; dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], max(dp[i][j], b[j] + a[k])); } } } int ans = INF; for (int i = 0; i < n; i++) ans = min(ans, dp[(1 << n) - 1][i]); cout << ans << endl; return 0; }