#include <bits/stdc++.h>
using namespace std;
long long n, c[20];
pair<long long, long long> a[200001];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> c[1] >> c[2];
    a[i * 2] = {c[1], 1};
    a[i * 2 + 1] = {c[2], -1};
  }
  sort(a, a + 2 * n);
  c[1] = 0;
  c[2] = 0;
  c[3] = 0;
  for (int i = 0; i < 2 * n; i++) {
    c[1] += a[i].second;
    if (c[1] > c[2]) {
      c[2] = c[1];
      c[3] = a[i].first;
    }
  }
  cout << c[3] << " " << c[2];
}
