#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  ;
  int n;
  cin >> n;
  pair<int, int> p[n];
  for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
  sort(p, p + n);
  int cnt = 1, ans = p[0].first;
  multiset<int> s;
  s.insert(p[0].second);
  for (int i = 1; i < n; i++) {
    while ((!s.empty()) && ((*s.begin()) <= p[i].first)) s.erase(s.begin());
    int temp = s.size() + 1;
    if (cnt < temp) {
      cnt = temp;
      ans = p[i].first;
    }
    s.insert(p[i].second);
  }
  cout << ans << " " << cnt;
}
