#include <bits/stdc++.h>
using namespace std;
vector<long long> seive() {
  long long n = 2;
  vector<long long> pr(200000, -1);
  for (int i = n; i < 200000; i++) {
    if (pr[i] == -1)
      pr[i] = 1;
    else
      continue;
    for (int j = 2 * i; j < 200000; j += i) pr[j] = 0;
  }
  return pr;
}
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= 1000000007;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
bool isprime(long long n) {
  bool flag = true;
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    map<long long, long long> mp;
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      mp[a]++;
      mp[b]--;
    }
    long long maxi = 0, ans = 0, sum = 0;
    for (auto i : mp) {
      sum = sum + i.second;
      if (maxi < sum) {
        maxi = sum;
        ans = i.first;
      }
    }
    cout << ans << " " << maxi << endl;
  }
}
