#include <bits/stdc++.h>
using namespace std;
using std::ios;
constexpr int MOD = 1e9 + 7;
constexpr int mod = 998244353;
template <typename T>
T power(T a, T b) {
  T r = 1;
  while (b) {
    if (b & 1) r *= a;
    b /= 2;
    a *= a;
  }
  return r;
}
int d[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int tt = 1;
  while (tt--) {
    int n;
    cin >> n;
    vector<int> b(n), d(n);
    map<int, int> ans;
    for (int i = 0; i < n; i++) {
      cin >> b[i] >> d[i];
      ans[b[i]]++;
      ans[d[i]]--;
    }
    int mx = 0, id = 0;
    int sum = 0;
    for (auto i : ans) {
      i.second += sum;
      sum = i.second;
      if (i.second > mx) {
        mx = i.second;
        id = i.first;
      }
    }
    cout << id << ' ' << mx;
  }
}
