#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<pair<int, int> > vec;
int n, ans1, ans2;
int main() {
cin >> n;
for(int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
vec.push_back({l, r});
}
sort(vec.begin(), vec.end(), [](pair<int, int> a, pair<int, int> b) {
return a.first < b.first;
});
int pre = vec[0].first, post = vec[0].first;
for(auto &elm : vec) {
if(elm.first > post) {
ans2 = max((elm.first - post), ans2);
ans1 = max((elm.second - elm.first), ans1);
pre = elm.first;
} else {
ans1 = max((elm.second - pre), ans1);
post = elm.second;
}
}
cout << ans1 << ' ' << ans2 << endl;
system("pause");
return 0;
}