#include <bits/stdc++.h>
using namespace std;
const long long M = 998244353;
long long a[101];
long long vis[101];
void dfs(int m, int b, vector<vector<long long> > v) {
  a[m] = b;
  vis[m] = 1;
  for (long long i = 0; i < v[m].size(); i++) {
    if (vis[v[m][i]] == 0) {
      if (a[m] == 1)
        dfs(v[m][i], 2, v);
      else
        dfs(v[m][i], 1, v);
    }
  }
}
int main() {
  long long n;
  cin >> n;
  map<long long, long long> m;
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    m[x]++;
    m[y]--;
  }
  long long sum = 0;
  long long ind = 0;
  long long ma = 0;
  for (auto i : m) {
    sum += i.second;
    if (sum > ma) {
      ma = sum;
      ind = i.first;
    }
  }
  cout << ind << " " << ma;
  return 0;
}
