#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second == b.second) {
    return a.first < b.first;
  }
  return a.second < b.second;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long>> p;
  for (long long i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    p.push_back({a, 1});
    p.push_back({b, -1});
  }
  sort(p.begin(), p.end());
  long long sum = 0;
  long long end = 0;
  long long y = 0;
  for (long long i = 0; i < 2 * n; i++) {
    sum += p[i].second;
    if (sum > end) {
      end = sum;
      y = p[i].first;
    }
  }
  cout << y << " " << end;
  return 0;
}
