#include <bits/stdc++.h>
using namespace std;
long long l[2000005], r[2000005], mi[2000005], n, ans, yea, tot, c[2000005];
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld%lld", &l[i], &r[i]);
    mi[++tot] = l[i], mi[++tot] = r[i];
  }
  sort(mi + 1, mi + tot + 1);
  long long un = unique(mi + 1, mi + tot + 1) - mi;
  for (long long i = 1; i <= n; i++) {
    long long L = lower_bound(mi + 1, mi + un + 1, l[i]) - mi;
    long long R = lower_bound(mi + 1, mi + un + 1, r[i]) - mi;
    c[L]++, c[R]--;
  }
  for (long long i = 1; i <= un; i++) {
    c[i] += c[i - 1];
    if (ans < c[i]) {
      ans = c[i];
      yea = mi[i];
    }
  }
  printf("%lld %lld", yea, ans);
}
