#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
long long int binpow(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) {
      res *= a;
      res %= 1000000007;
    }
    a *= a;
    a %= 1000000007;
    b >>= 1;
  }
  return res;
}
void solve() {
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int> > ints;
  for (long long int i = 0; i < n; i++) {
    long long int l, r;
    cin >> l >> r;
    ints.push_back({l, 1});
    ints.push_back({r, 0});
  }
  sort(ints.begin(), ints.end());
  long long int maxm = LONG_LONG_MIN;
  long long int maxdex = LONG_LONG_MAX;
  long long int cur = 0;
  for (long long int i = 0; i < ints.size(); i++) {
    if (ints[i].second)
      cur++;
    else
      cur--;
    if (cur >= maxm) {
      if (cur == maxm)
        maxdex = min(maxdex, ints[i].first);
      else {
        maxm = cur;
        maxdex = ints[i].first;
      }
    }
  }
  cout << maxdex << " " << maxm << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
