#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll modInverse(ll a, ll p) { return power(a, p - 2, p); }
ll fact(ll n) {
  ll result = 1;
  for (ll i = 1; i <= n; i++) result = (result * i);
  return result;
}
bool check(ll n, ll a) {
  ll t = 0;
  while (n != 0) {
    t++;
    n = n / 10;
  }
  if (t > a) return false;
  return true;
}
bool check(ll n) {
  if (ceil((double)sqrt(n)) == floor((double)sqrt(n))) {
    return 1;
  } else {
    return 0;
  }
}
ll Gans = 0;
ll Fans = 0;
ll find(ll arr[], ll n, ll sum) {
  unordered_map<ll, ll> prevSum;
  prevSum[0] = 1;
  ll res = 0;
  ll currsum = 0;
  for (ll i = 0; i < n; i++) {
    currsum += arr[i];
    if (prevSum.find(currsum - sum) != prevSum.end()) {
      prevSum.clear();
      prevSum[0] = 1;
      currsum = arr[i];
      res += 1;
    }
    prevSum[currsum]++;
  }
  return res;
}
bool correct(vector<ll> adj[], ll n, ll c[]) {
  for (ll i = 0; i < n; i++) {
    if (c[i] == 0) continue;
    for (auto it : adj[i]) {
      if (c[it] == 0) return false;
      if (c[i] == c[it]) return false;
    }
  }
  return true;
}
void solve(ll i, ll n, vector<ll> adj[], set<ll> &vis, ll c[], set<ll> &gvis) {
  vis.insert(i);
  gvis.insert(i);
  ll f = 0;
  for (ll j = 1; j <= 3; j++) {
    c[i] = j;
    ll f = 0;
    for (auto it : adj[i]) {
      if (c[it] != 0) continue;
      f = 1;
      solve(it, n, adj, vis, c, gvis);
    }
    if (!f) {
      if (correct(adj, n, c)) {
        Gans++;
      }
    }
    c[i] = 0;
  }
  return;
}
ll dp[505][505][22];
ll a[505][505];
ll b[505][505];
bool valid(ll i, ll j, ll n, ll m) {
  if (i >= n || j >= m || i < 0 || j < 0) return false;
  return true;
}
ll fun(ll i, ll j, ll n, ll m, ll k) {
  if (!valid(i, j, n, m)) {
    return 10000000000;
  } else {
    if (k == 0) {
      return 0;
    } else if (dp[i][j][k] != -1) {
      return dp[i][j][k];
    } else {
      ll ans = 10000000000;
      if (valid(i + 1, j, n, m)) {
        ans = min(ans, fun(i + 1, j, n, m, k - 1) + b[i][j]);
      }
      if (valid(i - 1, j, n, m)) {
        ans = min(ans, fun(i - 1, j, n, m, k - 1) + b[i - 1][j]);
      }
      if (valid(i, j - 1, n, m)) {
        ans = min(ans, fun(i, j - 1, n, m, k - 1) + a[i][j - 1]);
      }
      if (valid(i, j + 1, n, m)) {
        ans = min(ans, fun(i, j + 1, n, m, k - 1) + a[i][j]);
      }
      return dp[i][j][k] = ans;
    }
  }
}
int main() {
  ll n;
  cin >> n;
  map<ll, ll> mp;
  ll i, j;
  for (i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    mp[x]++;
    mp[y]--;
  }
  ll sum = 0;
  ll year = 0;
  ll ans = 0;
  for (auto it : mp) {
    sum += it.second;
    if (sum > ans) {
      ans = sum;
      year = it.first;
    }
  }
  cout << year << " " << ans << endl;
}
