#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
bool sortcol(const vector<int>& v1, const vector<int>& v2) {
  return v1[0] < v2[0];
}
int main() {
  int n;
  cin >> n;
  vector<vector<long long> > yr;
  long long max = 0, count = 0, year = 0;
  for (int a = 0; a < n; a++) {
    long long x, y;
    cin >> x >> y;
    yr.push_back({x, 1});
    yr.push_back({y, -1});
  }
  sort(yr.begin(), yr.end());
  for (int a = 0; a < 2 * n; a++) {
    count += yr[a][1];
    if (yr[a][1] == 1 && count > max) {
      max = count;
      year = yr[a][0];
    }
  }
  cout << year << " " << max << endl;
}
