#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, b, d, mx = 0, year = 0;
  cin >> n;
  vector<long long> vb, vd;
  map<long long, long long> mp;
  for (long long i = 1; i <= n; i++) {
    cin >> b >> d;
    vb.push_back(b);
    vd.push_back(d);
  }
  sort(vb.begin(), vb.end());
  sort(vd.begin(), vd.end());
  long long j = 0, sum = 0;
  for (long long i = 0; i < n; i++) {
    long long u = vb[i];
    if (vd[j] <= u) {
      while (vd[j] <= u) {
        j++;
        sum++;
      }
    }
    mp[u] = sum;
  }
  for (long long i = 0; i < n; i++) {
    long long alive = i + 1 - (mp[vb[i]]);
    if (mx < alive) {
      mx = alive;
      year = vb[i];
    }
  }
  cout << year << " " << mx << endl;
}
