#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int ispalindrome(string ss) {
  long long int n = ss.size();
  for (long long int i = 0; i < (n + 1) / 2; i++) {
    if (ss[i] != ss[n - i - 1]) return 0;
  }
  return 1;
}
long long int digit(long long int n) {
  long long int res = 0;
  while (n) {
    res++;
    n = n / 10;
  }
  return res;
}
long long int mod = 1e9 + 7;
long long int fact(long long int n) {
  long long int ans = 1;
  for (long long int i = 1; i < n + 1; i++) ans = ((ans * i) % mod);
  return ans % mod;
}
long long int isprime(long long int n) {
  if (n == 2 || n == 3) return 1;
  for (long long int i = 2; i < sqrt(n) + 1; i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
long long int k = 0;
void solve() {
  long long int n, a, b;
  cin >> n;
  map<long long int, long long int> mp;
  for (long long int i = 0; i < n; i++) {
    cin >> a >> b;
    mp[a]++;
    mp[b]--;
  }
  int x = 0, y = 0, mx = 0;
  for (auto it : mp) {
    x += it.second;
    if (x > mx) {
      mx = x;
      y = it.first;
    }
  }
  cout << y << " " << mx << endl;
}
int main() {
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
}
