#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<pair<long long int, long long int> > tim;
  long long int b, d;
  for (int i = 0; i < n; i++) {
    cin >> b >> d;
    tim.push_back({b, 1});
    tim.push_back({d, 0});
  }
  sort(tim.begin(), tim.end());
  long long int ans = 0;
  long long int year = 1e9;
  long long int cur = 0;
  for (int i = 0; i < tim.size(); i++) {
    if (tim[i].second == 0) {
      --cur;
      continue;
    }
    ++cur;
    if (cur > ans) {
      ans = cur;
      year = tim[i].first;
    }
  }
  cout << year << " " << ans;
  return 0;
}
