#include <bits/stdc++.h>
using namespace std;
template <typename a>
void SWAP(a &b, a &c) {
  a d = b;
  b = c;
  c = d;
}
long long power(long long a, long long b) {
  long long result = 1;
  while (b) {
    if (b & 1) result = a * result;
    a *= a;
    b >>= 1;
  }
  return result;
}
long long gcd(long long a, long long b) {
  while (b) {
    a = a % b;
    SWAP(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }
long long check_double_equality(double a, double b) {
  double c = (((a - b) > 0) ? (a - b) : (-(a - b)));
  if (c < 1e-9)
    return true;
  else
    return false;
}
bool sol(pair<long long, long long> a, pair<long long, long long> b) {
  long long val1 = (((a.first - a.second) > 0) ? (a.first - a.second)
                                               : (-(a.first - a.second)));
  long long val2 = (((b.first - a.second) > 0) ? (b.first - a.second)
                                               : (-(b.first - a.second)));
  return val1 > val2;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  pair<long long, long long> bd[n];
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    cin >> bd[i].first >> bd[i].second;
    mp[bd[i].first]++;
    mp[bd[i].second]--;
  }
  pair<long long, long long> ans = {0, 0};
  long long temp = 0;
  bool first = true;
  for (auto &it : mp) {
    if (first) {
      first = false;
      temp = it.second;
      ans = it;
    } else {
      it.second += temp;
      temp = it.second;
      if (ans.second < it.second) {
        ans = it;
      }
    }
  }
  cout << ans.first << " " << ans.second << endl;
  return 0;
}
