#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> start(n), end(n);
  for (int i = 0; i < n; ++i) {
    cin >> start[i] >> end[i];
  }
  sort(start.begin(), start.end());
  sort(end.begin(), end.end());
  int s = 0;
  int e = 0;
  int ma = 0;
  int occ = 0;
  int an = 0;
  while (s < start.size()) {
    if (start[s] < end[e]) {
      occ++;
      if (ma < occ) {
        ma = occ;
        an = start[s];
      }
      s++;
    } else {
      e++;
      occ--;
    }
  }
  cout << an << " " << ma << "\n";
  return 0;
}
