#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<long long, long long>> a(2 * n);
  for (int i = 0; i < n; i++) {
    long long f, s;
    cin >> f >> s;
    a[i] = {f, 1};
    a[i + n] = {s, -1};
  }
  sort(a.begin(), a.end());
  long long max = 1, sum = 0, nyear = a[0].first;
  for (int i = 0; i < 2 * n; i++) {
    sum += a[i].second;
    if (sum > max) {
      max = sum;
      nyear = a[i].first;
    }
  }
  cout << nyear << " " << max << endl;
}
