#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e9 + 7;
const double pie = 3.14159265358979323846;
const char nl = '\n';
const char spc = ' ';
template <typename Type>
istream &operator>>(istream &in, vector<Type> &v) {
  long long int n = v.size();
  for (int i = 0; i < n; i++) in >> v[i];
  return in;
}
template <typename Type>
ostream &operator<<(ostream &out, vector<Type> &v) {
  for (auto value : v) out << value << ' ';
  out << nl;
  return out;
}
bool isPrime(long long int n) {
  if (n < 4) return true;
  if (n % 2 == 0) return false;
  long long int i = 3;
  while (i * i <= n) {
    if (n % i == 0) return false;
    i += 2;
  }
  return true;
}
void solve() {
  long long int n;
  cin >> n;
  map<long long int, long long int> m;
  while (n--) {
    long long int x, y;
    cin >> x >> y;
    m[x]++;
    m[y]--;
  }
  long long int c = 0, mx = 0, year = 0;
  for (auto it : m) {
    c += it.second;
    if (c > mx) {
      mx = c;
      year = it.first;
    }
  }
  cout << year << ' ' << mx << nl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
