A. Hacker Cups and Balls

time limit per test

4 secondsmemory limit per test

512 mebibytesinput

standard inputoutput

standard outputThe dark side of Dreamoon, Ademnoor, wants to play an interesting game with you. Did you hear about the game "cups and balls"? Here is the hacker version of it!

There are *n* cups and *n* balls, both are numbered 1, 2, ..., *n*. At each moment of time, there is exactly one ball in each cup. Initially, *a*_{i}-th ball is placed in the *i*-th cup. Admenoor will perform *m* magic operations on these balls and cups. The *i*-th operation will sort all the balls in the cups numbered between *l*_{i} and *r*_{i}, inclusive. The sorting could be performed in either ascending order or descending order. After these *m* operations, you need to answer which ball is placed in the center cup. We guarantee that *n* will be an odd integer, so the center cup means the -th cup.

For example, consider *n* = 5, *m* = 2 and *a* = [5, 1, 4, 2, 3]. If the first operation is to sort the balls in the cups numbered between 1 and 4 in ascending order, then *a* would become [1, 2, 4, 5, 3]. If the second operation is to sort the balls in the cups numbered between 2 and 5 in descending order, then *a* would become [1, 5, 4, 3, 2]. In this example, the number of the ball in the center cup after all operations is 4.

Input

The first line of input contains two integers *n* and *m*. The following line contains *n* integers *a*_{1}, *a*_{2}, ..., *a*_{n}. Each of the following *m* lines contains two integers *l*_{i} and *r*_{i}. If *l*_{i} < *r*_{i}, Admenoor will sort that balls in ascending order in this operation; otherwise, the balls will be sorted in descending order in this operation.

- 1 ≤
*n*≤ 99 999 -
*n*is an odd integer - 0 ≤
*m*≤ 10^{5} - 1 ≤
*a*_{i}≤*n* - is a permutation of 1, 2, ...,
*n* - 1 ≤
*l*_{i},*r*_{i}≤*n*

Output

Output a single line with the number of the ball in the center cup after all operations.

Examples

Input

3 2

1 3 2

1 3

3 1

Output

2

Input

5 2

5 1 4 2 3

1 4

5 2

Output

4

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jan/29/2020 09:47:14 (e1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|