#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
struct node {
  int year;
  int num;
} no[2 * maxn];
bool cmp(node A, node B) {
  if (A.year == B.year)
    return A.num < B.num;
  else
    return A.year < B.year;
}
int main() {
  int n, b, d;
  cin >> n;
  for (int i = 0; i < 2 * n; i += 2) {
    cin >> b >> d;
    no[i].year = b;
    no[i].num = 1;
    no[i + 1].year = d;
    no[i + 1].num = -1;
  }
  sort(no, no + 2 * n, cmp);
  int ansyear, people = 0, ansnum = 0;
  for (int i = 0; i < 2 * n; i++) {
    people += no[i].num;
    if (people > ansnum) {
      ansnum = people;
      ansyear = no[i].year;
    }
  }
  cout << ansyear << " " << ansnum << endl;
  return 0;
}
