#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> v;
  for (long long i = 0; i < n; i++) {
    long long b, d;
    cin >> b >> d;
    v.push_back({b, 1});
    v.push_back({d, 0});
  }
  sort(v.begin(), v.end());
  long long alive = 0, maxl = 0, miny;
  for (auto i : v) {
    if (i.second) {
      alive++;
      if (alive > maxl) {
        maxl = alive;
        miny = i.first;
      }
    } else {
      alive--;
    }
  }
  cout << miny << " " << maxl;
  return 0;
}
