#include <bits/stdc++.h>
using namespace std;
long long checkprime(long long a) {
  int i;
  int flag = 1;
  for (i = 2; i <= sqrt(a); i++) {
    if (a % i == 0) {
      flag = 0;
      break;
    }
  }
  return flag;
}
long long max(long long a, long long b) {
  if (a >= b)
    return a;
  else
    return b;
}
int main() {
  int n, i;
  cin >> n;
  vector<pair<long long, long long>> v;
  for (i = 0; i < n; i++) {
    long long left, right;
    cin >> left >> right;
    v.push_back(make_pair(left, 1));
    v.push_back(make_pair(right, 0));
  }
  sort(v.begin(), v.end());
  long long ans = 0;
  long long year = 0;
  long long ind = 0;
  for (i = 0; i < v.size(); i++) {
    if (v[i].second == 1) {
      ind++;
      if (ind > ans) {
        ans = ind;
        year = v[i].first;
      }
    } else if (v[i].second == 0)
      ind--;
  }
  cout << year << " " << ans << endl;
}
