#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long b[n], d[n];
  priority_queue<long long, vector<long long>, greater<long long>> pq;
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    cin >> b[i] >> d[i];
    pq.push(b[i]);
    pq.push(d[i]);
    mp[b[i]]++;
    mp[d[i]]--;
  }
  long long year, ans = 0, s = 0, y;
  while (!pq.empty()) {
    long long x = pq.top();
    if (y == x) {
      pq.pop();
      continue;
    }
    s += (mp[x]);
    if (ans < s) {
      ans = s;
      year = x;
    }
    y = x;
    pq.pop();
  }
  cout << year << " " << ans;
}
