#include <bits/stdc++.h>
using namespace std;
#define more ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl "\n"
#define pb push_back
#define FloatCout std::cout << std::fixed << std::setprecision(10)
const int N = 2e5 + 5, MOD = 1e9 + 7, inf = 0x3f3f3f3f;
const long long INF = 1e18;
typedef long long LL;
typedef unsigned long long usLL;
typedef pair<int, int> PII;
inline void solve()
{
LL n; cin >> n;
std::vector<pair<LL, LL>> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
a[0] = make_pair(a[1].first, a[1].first);
LL ans1 = 0, ans2 = 0, len = 0, r = a[1].first;
for (int i = 1; i <= n; i++)
{
if (a[i].first <= r)
{
len += max(a[i].second - r, 1LL * 0);
r = max(r, a[i].second);
}
else
{
ans1 = max(len, ans1);
ans2 = max(ans2, a[i].first - r);
r = max(r, a[i].second);
len = 0;
}
}
ans1 = max(len, ans1);
cout << ans1 << ' ' << ans2 << endl;
}
int main()
{
more;
solve();
return 0;
}