#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  while (n--) {
    int n1, n2;
    cin >> n1 >> n2;
    mp[n1]++;
    mp[n2]--;
  }
  int cur = 0, sum = 0, peo = 0;
  for (auto it : mp) {
    cur += it.second;
    if (cur > sum) {
      sum = cur;
      peo = it.first;
    }
  }
  cout << peo << " " << sum << endl;
  return 0;
}
