#include <bits/stdc++.h>
using namespace std;
struct comp {
  bool operator()(pair<long long int, long long int> a,
                  pair<long long int, long long int> b) {
    if (a.first == b.first) return a.second > b.second;
    return a.first > b.first;
  }
};
void solve(long long int test) {
  long long int n, b, d;
  cin >> n;
  map<long long int, long long int> m;
  set<long long int> s;
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int> >, comp>
      q, q1;
  for (long long int i = 0; i < n; i++) {
    cin >> b >> d;
    m[b]++;
    m[d]--;
  }
  long long int year, ans = 0, curr = 0;
  map<long long int, long long int>::iterator itr;
  for (itr = m.begin(); itr != m.end(); itr++) {
    curr += itr->second;
    if (curr > ans) {
      ans = curr;
      year = itr->first;
    }
  }
  cout << year << " " << ans << endl;
}
int main() {
  long long int t = 1, test = 1;
  while (t--) {
    solve(test++);
  }
  return 0;
}
