#include #include #include #include #include using namespace std; int main() { int ans = INT_MAX, tmp; size_t N; cin >> N; vector> AB(N); for (size_t i = 0; i < N; ++i) cin >> AB[i].first >> AB[i].second; sort(AB.begin(), AB.end()); do { tmp = 0; for (size_t i = 1; i < N; ++i) tmp = max(tmp, AB[i - 1].second - AB[i - 1].first + AB[i].first); ans = min(ans, tmp); } while (next_permutation(AB.begin(), AB.end())); cout << ans; }