cswork / OAOpen practice workspace

IBMOA #30

Get Max Traffic Time

Estimated MediumJudge-ready

Topics (AI-labelled)Prefix & Ranges

Each visitor is online during the closed interval [start,end]. Find the earliest integer time at which the number of visitors online at the same time is the largest.

Input

The first line contains n, followed by n lines of start end. 1≤n≤100000, 1≤start≤end; the source's upper bound on time is truncated, so this site adds end≤10^9.

Output

Output one integer, the answer.

Example 1

Input:

4
1 7
6 8
2 6
9 10

Output:

6

Example 2

Input:

2
1 1
2 2

Output:

1

Example 3

Input:

2
4 4
4 8

Output:

4

Example notes

The examples give 6, 1 and 4 respectively; a visitor is still online at the end point, and ties go to the earliest time.

Editorial

Loading solution…