#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::unordered_map<int, int> births;
  std::unordered_map<int, int> deaths;
  std::set<int> significantYears;
  int minBirth = 0, maxDeath = 0;
  for (int i = 0; i < n; i++) {
    int b, d;
    std::cin >> b >> d;
    significantYears.insert(b);
    significantYears.insert(d);
    if (minBirth > b) {
      minBirth = b;
    }
    if (maxDeath < d) {
      maxDeath = d;
    }
    if (births.find(b) != births.end()) {
      births[b]++;
    } else {
      births[b] = 1;
    }
    if (deaths.find(d) != deaths.end()) {
      deaths[d]++;
    } else {
      deaths[d] = 1;
    }
  }
  int number = 0, maxNum = 0, maxYear = 0;
  for (auto it = significantYears.begin(); it != significantYears.end(); it++) {
    if (births.find(*it) != births.end()) {
      number += births[*it];
    }
    if (deaths.find(*it) != deaths.end()) {
      number -= deaths[*it];
    }
    if (maxNum < number) {
      maxNum = number;
      maxYear = *it;
    }
  }
  std::cout << maxYear << " " << maxNum << "\n";
}
