#include <bits/stdc++.h>
using namespace std;
const int N = 3.5e5, M = 1.5e6;
long long ar[N], br[N];
long long n, m, k;
void answer() {
  cin >> n;
  vector<pair<long long, long long> > v;
  for (int i = 1; i <= n; i++) {
    long long a, b;
    cin >> a >> b;
    v.push_back({a, -1});
    v.push_back({b, 1});
  }
  sort(v.begin(), v.end());
  v.push_back({2e9, -1});
  long long sum = 0, year = 0, ma = 0;
  for (int i = 0; i < v.size(); i++) {
    sum -= v[i].second;
    if (sum > ma && (v[i]).first < (v[i + 1]).first) {
      ma = sum;
      year = v[i].first;
    }
  }
  cout << year << " " << ma << endl;
  return;
}
int main() {
  answer();
  return 0;
}
