#include <bits/stdc++.h>
using namespace std;
const int INF = 1e6 + 5;
const int mod = 1e9 + 7;
struct life {
  int st, end;
};
void solve(int case_num) {
  int n;
  cin >> n;
  int s, e;
  vector<pair<int, int>> span(2 * n);
  for (int i = 0; i < n; i++) {
    cin >> s >> e;
    span[2 * i] = {s, 1};
    span[2 * i + 1] = {e, -1};
  }
  long long mx = LONG_MIN, year = 0, curr = 0;
  sort(span.begin(), span.end());
  for (auto a : span) {
    if (a.second == 1) {
      curr++;
      if (mx < curr) {
        mx = curr;
        year = a.first;
      }
    } else {
      curr--;
    }
  }
  cout << year << " " << mx << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int cases = 1;
  for (int i = 0; i < cases; i++) {
    solve(i);
  }
  return 0;
}
