#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b);
long long int power(long long int a, long long int b);
long long int powerwithmod(long long int a, long long int b);
long long int nCr(long long int n, long long int r);
long long int fact(long long int n);
bool cmp(pair<long long int, long long int> a,
         pair<long long int, long long int> b) {
  if (a.first < b.first)
    return true;
  else if (a.first > b.first)
    return false;
  else {
    if (a.second > b.second)
      return true;
    else
      return false;
  }
}
void solve() {
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int>> sol;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    sol.push_back(make_pair(x, -1));
    sol.push_back(make_pair(y, 1));
  }
  long long int maxmy = 0, maxp = 0;
  long long int cnt = 0;
  sort(sol.begin(), sol.end(), cmp);
  for (int i = 0; i < sol.size(); i++) {
    if (sol[i].second == -1) {
      cnt++;
      if (maxp < cnt) {
        maxmy = sol[i].first;
        maxp = cnt;
      }
    } else {
      cnt--;
    }
  }
  cout << maxmy << " " << maxp;
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int powerwithmod(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res % 1000000007;
}
long long int power(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a);
    a = (a * a);
    b >>= 1;
  }
  return res;
}
long long int nCr(long long int n, long long int r) {
  return fact(n) / (fact(r) * fact(n - r));
}
long long int fact(long long int n) {
  long long int res = 1;
  for (long long int i = 2; i <= n; i++) res = (res * i) % 1000000007;
  return (res) % 1000000007;
}
