#include <bits/stdc++.h>
using namespace std;
using ii = pair<long long, long long>;
using vii = vector<ii>;
using vi = vector<long long>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vvb = vector<vb>;
const long long N = 1e5 + 5, MOD = 1e9 + 7, INF = 1e9 + 5;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  long long n;
  cin >> n;
  vi l, r;
  for (long long i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    l.push_back(x);
    r.push_back(y);
  }
  sort((l).begin(), (l).end());
  sort((r).begin(), (r).end());
  long long year = -1, run = 0, best = 0;
  for (long long i = 0, j = 0; i < n; i++) {
    run++;
    while (j < n && r[j] <= l[i]) {
      j++;
      run--;
    }
    if (run > best) {
      best = run;
      year = l[i];
    }
  }
  cout << year << " " << best;
}
