#include <bits/stdc++.h>
const int Max = 50006;
const int Inf = 2e9;
const long long MOD = 1e9 + 7;
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int> > v;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back({x, 1});
    v.push_back({y, 0});
  }
  sort(v.begin(), v.end());
  int year = 0, cnt = 0;
  int aux_cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i].second == 1) {
      aux_cnt++;
      if (aux_cnt > cnt) {
        cnt = aux_cnt;
        year = v[i].first;
      }
    } else
      aux_cnt--;
  }
  cout << year << " " << cnt << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
