#include <bits/stdc++.h>
using namespace std;
map<int, int> mymap;
int main() {
  int i, ans = 0, nr_oameni = 0, n, x, y, sum = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x >> y;
    mymap[x]++;
    mymap[y]--;
  }
  for (auto it : mymap) {
    sum += it.second;
    if (sum > ans) {
      ans = sum;
      nr_oameni = it.first;
    }
  }
  cout << nr_oameni << " " << ans;
  return 0;
}
