#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, b, d, max = -1, c = 0, y;
  map<long long int, long long int> mape;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> b;
    cin >> d;
    mape[b]++;
    mape[d]--;
  }
  for (auto x : mape) {
    c = c + x.second;
    if (c > max) {
      max = c;
      y = x.first;
    }
  }
  cout << y << " " << max;
  return 0;
}
