#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, n, m, x, y, mm = 0, yr, sum = 0;
  cin >> n;
  map<long long, long long> a;
  for (i = 0; i < n; i++) {
    cin >> x;
    cin >> y;
    a[x]++;
    a[y]--;
  }
  map<long long, long long>::iterator it;
  for (it = a.begin(); it != a.end(); it++) {
    sum = sum + a[it->first];
    if (sum > mm) {
      mm = sum;
      yr = it->first;
    }
  }
  cout << yr << " " << mm;
  return 0;
}
