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