#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, a, i, b, j, k, t, x, y, z, tc, u, v, w;
  cin >> tc;
  set<long long>::iterator itr;
  set<long long> st;
  vector<pair<long long, long long> > v2;
  vector<long long>::iterator it;
  vector<long long> vct;
  t = 0;
  long long sum[200005] = {0};
  long long ans[200005] = {0};
  for (i = 0; i < tc; i++) {
    cin >> x >> y;
    pair<long long, long long> p1;
    p1.first = x;
    p1.second = y;
    v2.push_back(p1);
    st.insert(x);
    st.insert(y);
  }
  for (itr = st.begin(); itr != st.end(); itr++) vct.push_back(*itr);
  for (i = 0; i < tc; i++) {
    u = v2[i].first;
    v = v2[i].second;
    it = lower_bound(vct.begin(), vct.end(), u);
    k = it - vct.begin();
    sum[k]++;
    it = lower_bound(vct.begin(), vct.end(), v);
    if (it != vct.end()) sum[it - vct.begin()]--;
  }
  z = 0;
  for (i = 0; i < tc; i++) {
    if (i == 0)
      ans[i] = sum[i];
    else
      ans[i] = ans[i - 1] + sum[i];
    z = max(ans[i], z);
  }
  for (i = 0; i < tc; i++) {
    if (ans[i] == z) {
      cout << vct[i] << " " << z << endl;
      return 0;
    }
  }
}
