#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  map<int, int> mp;
  while (n--) {
    long long b, d;
    cin >> b >> d;
    mp[b]++;
    mp[d]--;
  }
  long long cur = 0, y = 0, num = 0;
  for (auto i : mp) {
    cur += i.second;
    if (cur > y) {
      y = cur;
      num = i.first;
    }
  }
  cout << num << " " << y << endl;
}
