#include <bits/stdc++.h>
using namespace std;
void sol() {}
static bool comp(pair<long long, long long> b, pair<long long, long long> a) {
  return b.second < a.second;
}
int main() {
  int n;
  cin >> n;
  map<long long, long long> mp;
  for (int i = 0; i < n; i++) {
    long long b, d;
    cin >> b >> d;
    mp[b]++;
    mp[d]--;
  }
  long long sum = 0;
  int y = 0, k = 0;
  for (auto& it : mp) {
    sum += it.second;
    if (sum > k) {
      k = sum;
      y = it.first;
    }
  }
  cout << y << ' ' << k << endl;
}
