#include <bits/stdc++.h>
using namespace std;
using u64 = uint64_t;
void solve() {
  long long n;
  cin >> n;
  map<long long, long long> m;
  long long x, y;
  for (int i = 0; i < n; i++) cin >> x >> y, m[x]++, m[y]--;
  long long ans = 0, yr = 0, sum = 0;
  for (auto x : m) {
    sum += x.second;
    if (sum > ans) ans = sum, yr = x.first;
  }
  cout << yr << " " << ans << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1LL;
  while (t--) {
    solve();
  }
}
