Under construction

Still being built. Things may change

Cheater Search

Interview

Time limit2sMemory limit1024 MB

Summary
Find a contiguous cheater interval [l, r] so that cheaters' claimed ranges avoid it and every non-cheater's claimed range overlaps it.
Level

Medium6 of 10

Topics
Two pointers, Prefix sum, Array
Solved
No attempts yet

Problem

There are NN pidols numbered from 11 to NN, all distinct. Some of them are cheaters, and their numbers are consecutive. Specifically, for some integers ll, rr (1≤l≤r≤N)(1 \leq l \leq r \leq N), pidols ll through rr are all cheaters, and every other pidol is not a cheater.

Pidol ii claims that at least one cheater is among the pidols numbered from aia_i to bib_i inclusive. If pidol ii is not a cheater, the claim is true. However, all cheaters lie. That is, if pidol ii is a cheater, then no cheater is among the pidols numbered aia_i to bib_i.

Input

The first line contains the number of pidols NN. (2≤N≤200 000)(2 \leq N \leq 200\ 000)

Each of the next NN lines contains two integers aia_i and bib_i, separated by a space. The line i+1i+1 gives the claim of pidol ii, that at least one cheater is among the pidols numbered from aia_i to bib_i. (1≤ai≤bi≤N)(1 \leq a_i \leq b_i \leq N)

Output

Print two integers ll and rr separated by a space, a valid pair that satisfies all the claims. If several answers exist, print any one of them.

Examples1

  1. Example 1

    Input
    6
    3 4
    4 5
    1 1
    1 4
    1 2
    2 6
    
    Expected output
    2 3