#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  int n;
  cin >> n;
  map<int, int> m;
  while (n--) {
    int x, y;
    cin >> x >> y;
    m[x]++;
    m[y]--;
  }
  int year, sum = 0, ans = 0;
  for (auto it : m) {
    sum += it.second;
    if (sum > ans) {
      ans = sum;
      year = it.first;
    }
  }
  cout << year << " " << ans << endl;
  return 0;
}
