#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, b, d;
  cin >> n;
  map<long long, long long> mp;
  for (long long i = 1; i <= n; i++) {
    cin >> b >> d;
    mp[b]++;
    mp[d]--;
  }
  long long sum = 0, mx = 0, tar_year = 0;
  for (auto [x, y] : mp) {
    sum += y;
    if (sum > mx) {
      mx = sum;
      tar_year = x;
    }
  }
  cout << tar_year << " " << mx << endl;
}
