#include <bits/stdc++.h>
using namespace std;
int main() {
  int in;
  cin >> in;
  vector<pair<int, bool>> vec;
  for (int i = 0; i < in; i++) {
    int x, y;
    cin >> x >> y;
    vec.push_back({x, 0});
    vec.push_back({y - 1, 1});
  }
  sort(vec.begin(), vec.end());
  int count = 0, maxcount = 0, year;
  for (int i = 0; i < vec.size(); i++) {
    if (vec[i].second == 0) {
      count++;
    } else {
      count--;
    }
    if (count > maxcount) {
      year = vec[i].first;
      maxcount = count;
    }
  }
  cout << year << ' ' << maxcount << '\n';
  return 0;
}
