#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n = 0, birth = 0, death = 0;
  cin >> n;
  vector<pair<int, int> > vp;
  for (int i = 0; i < n; ++i) {
    cin >> birth >> death;
    vp.emplace_back(birth, 1);
    vp.emplace_back(death, 0);
  }
  sort(vp.begin(), vp.end());
  int res = 0, t = 0, year = 0;
  for (auto i : vp) {
    if (i.second == 1) {
      ++t;
      if (res < t) {
        res = t;
        year = i.first;
      }
    } else
      --t;
  }
  cout << year << " " << res;
}
