시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
3 초 512 MB 2 2 2 100.000%

문제

The 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, \ldots, 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 $\frac{n + 1}{2}$-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$.

입력

The first line of input contains two integers $n$ and $m$. The following line contains $n$ integers $a_1, a_2, \ldots, 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.

출력

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

제한

  • $1 \le n \le 99\,999$
  • $n$ is an odd integer
  • $0 \le m \le 10^5$
  • $1 \le a_i \le n$
  • $\langle a_i \rangle$ is a permutation of $1, 2, \ldots, n$
  • $1 \le l_i, r_i \le n$

예제 입력 1

3 2
1 3 2
1 3
3 1

예제 출력 1

2

예제 입력 2

5 2
5 1 4 2 3
1 4
5 2

예제 출력 2

4