#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> a;
  set<int> t;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    a[x]++;
    a[y]--;
    t.insert(x);
    t.insert(y);
  }
  long long int sum = 0;
  int year = 0, p = 0;
  for (int i : t) {
    sum += a[i];
    if (sum > p) {
      p = sum;
      year = i;
    }
  }
  cout << year << ' ' << p << endl;
  return 0;
}
