#include <bits/stdc++.h>
using namespace std;
void setup() { ios_base::sync_with_stdio(false); }
void solve() {
  long n;
  cin >> n;
  multiset<pair<long, bool>> deaths;
  long b, d;
  for (int i = 0; i < n; i++) {
    cin >> b >> d;
    deaths.insert(make_pair(b, 1));
    deaths.insert(make_pair(d, 0));
  }
  long maximum = 0;
  long maxyear = 1;
  long current = 0;
  for (auto p : deaths) {
    if (p.second) {
      current++;
    } else {
      current--;
    }
    if (current > maximum) {
      maximum = current;
      maxyear = p.first;
    }
  }
  cout << maxyear << " " << maximum << endl;
}
void test() {
  long long T;
  cin >> T;
  for (long long t = 1; t <= T; t++) {
    solve();
  }
}
int main() {
  setup();
  solve();
}
