Hacker Cups and Balls

아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

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 nn cups and nn balls, both are numbered 1,2,,n1, 2, \ldots, n. At each moment of time, there is exactly one ball in each cup. Initially, a_ia\_i-th ball is placed in the ii-th cup. Admenoor will perform mm magic operations on these balls and cups. The ii-th operation will sort all the balls in the cups numbered between l_il\_i and r_ir\_i, inclusive. The sorting could be performed in either ascending order or descending order. After these mm operations, you need to answer which ball is placed in the center cup. We guarantee that nn will be an odd integer, so the center cup means the n+12\frac{n + 1}{2}-th cup.

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

입력

The first line of input contains two integers nn and mm. The following line contains nn integers a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n. Each of the following mm lines contains two integers l_il\_i and r_ir\_i. If l_i<r_il\_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.

제한

  • 1n99,9991 \le n \le 99\\,999
  • nn is an odd integer
  • 0m1050 \le m \le 10^5
  • 1a_in1 \le a\_i \le n
  • a_i\langle a\_i \rangle is a permutation of 1,2,,n1, 2, \ldots, n
  • 1l_i,r_in1 \le l\_i, r\_i \le n