#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long M = (long long)1e9 + 7;
const long long inf = (long long)1e18;
const double pi = 2 * acos(0.0);
const double esp = 1e-9;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
vector<pair<int, int> > v1;
int main() {
  int test = 1;
  for (int cs = 1; cs <= test; ++cs) {
    int n, mx = 0, in = 0, ct = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      int x, y;
      cin >> x >> y;
      v1.push_back({x, 1});
      v1.push_back({y, -1});
    }
    sort(v1.begin(), v1.end());
    for (int i = 0; i < (int)v1.size(); ++i) {
      if (v1[i].second == 1) {
        ++ct;
      } else {
        --ct;
      }
      if (mx < ct) {
        mx = ct;
        in = v1[i].first;
      }
    }
    cout << in << " " << mx << "\n";
  }
  return 0;
}
