#include <bits/stdc++.h>
using namespace std;
long long const nax = 2e5;
long long const M = 1e9;
void solve() {
  long long n;
  cin >> n;
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    long long x;
    long long y;
    cin >> x >> y;
    mp[x]++;
    mp[y]--;
  }
  long long ans = 0;
  long long y = 0;
  long long sum = 0;
  for (auto x : mp) {
    sum += x.second;
    if (sum > ans) {
      ans = sum;
      y = x.first;
    }
  }
  cout << y << " " << ans << '\n';
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long t = 1, z = 1;
  while (t--) {
    solve();
  }
}
