#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int N = 2e5 + 7;
int Dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int Dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long powm(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2) res *= a;
    a *= a;
    b /= 2;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int> > v(n), p;
  for (auto& i : v) {
    cin >> i.first >> i.second;
    p.push_back({i.first, 1});
    p.push_back({i.second, -1});
  }
  sort(p.begin(), p.end());
  long long cnt = 0, idx = 0, mx = 0;
  for (auto a : p) {
    if (a.second == 1) {
      cnt++;
      if (cnt > mx) {
        mx = cnt;
        idx = a.first;
      }
    } else
      cnt--;
  }
  cout << idx << " " << mx;
  return 0;
}
