#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<pair<int, int> > events;
  while (n--) {
    int a, b;
    cin >> a >> b;
    events.push_back({a, 1});
    events.push_back({b, 0});
  }
  sort(events.begin(), events.end());
  int mx = 0, t = 0, mans = 0;
  for (auto x : events) {
    if (x.second == 0)
      mans--;
    else {
      mans++;
      if (mx < mans) t = x.first, mx = mans;
    }
  }
  cout << t << " " << mx << endl;
  return 0;
}
