#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
long long int inf = 0x3f3f3f3f3f3f3f3f;
const long long int mod = 1e9 + 7;
const long long int mx = 5 * 1000000;
bool cmp(pair<long long int, long long int> a,
         pair<long long int, long long int> b) {
  if (a.first != b.first) return a.first < b.first;
  return a.second > b.second;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int>> a;
  for (long long int i = 0; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    a.push_back({x, y});
  }
  sort(a.begin(), a.end(), cmp);
  map<long long int, long long int> val;
  set<long long int> aa;
  for (auto [x, y] : a) {
    aa.insert(x);
    aa.insert(y);
    val[x]++;
    if (val[y] != 0)
      val[y]--;
    else
      val[y] = -1;
  }
  long long int sum = 0;
  long long int ans = 0, cnt = 0;
  for (auto x : aa) {
    sum += val[x];
    if (sum > ans) {
      ans = sum;
      cnt = x;
    }
  }
  cout << cnt << " " << ans << endl;
}
