#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int> > arr(n);
  set<long long int> s;
  for (int i = 0; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    arr.push_back({x, y});
    s.insert(x);
    s.insert(y);
  }
  long long int len = s.size();
  vector<long long int> v;
  for (auto x : s) v.push_back(x);
  vector<long long int> a(len);
  for (auto x : arr) {
    long long int i = x.first, j = x.second;
    long long int itr = lower_bound(v.begin(), v.end(), i) - v.begin();
    a[itr]++;
    itr = lower_bound(v.begin(), v.end(), j) - v.begin();
    a[itr]--;
  }
  for (int i = 1; i < len; i++) a[i] += a[i - 1];
  long long int year = 0, pop = 0;
  for (int i = 0; i < len; i++) {
    if (a[i] > pop) {
      pop = a[i];
      year = v[i];
    }
  }
  cout << year << " " << pop << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tst = 1;
  while (tst--) solve();
  return 0;
}
