#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, b, d, cnt = 1;
  cin >> n;
  vector<long long> vb, vd;
  long long mx = 0, year = 0;
  map<long long, long long> mp, mp1;
  for (long long i = 1; i <= n; i++) {
    cin >> b >> d;
    vb.push_back(b);
    vd.push_back(d);
    mp[d]++;
  }
  sort(vb.begin(), vb.end());
  sort(vd.begin(), vd.end());
  long long sum = 0, pre = -1;
  for (auto x : vd) {
    if (pre != x) {
      sum += mp[x];
      mp1[x] = sum;
      pre = x;
    }
  }
  for (long long i = 0; i < n; i++) {
    long long birth = i + 1;
    long long val = *upper_bound(vd.begin(), vd.end(), vb[i]);
    long long dead = mp1[val] - mp[val];
    long long alive = birth - dead;
    if (alive > mx) {
      mx = alive;
      year = vb[i];
    }
  }
  cout << year << " " << mx << endl;
}
