Most Influential Pumpkin

No attempts yetTime limit5sMemory limit256 MB

Problem

The pumpkins in Hagrid's garden have come to life. They walk, they talk, they date, and of course they hold elections to choose the Head Pumpkin. Guessing the winner is easy. Line all the pumpkins up sorted by size, and the pumpkin standing exactly in the middle becomes the Head Pumpkin.

Hagrid wants no fuss in his garden, so he wants to know who the Head Pumpkin is. When several pumpkins share the same size he cannot tell which one of them holds the title, but knowing the size of the Head Pumpkin is enough for him.

The pumpkins grow in a row, numbered from 1 to NN. Hagrid often waters a group of pumpkins that grow next to each other. He picks two numbers SS and TT and waters every pumpkin from the SS-th to the TT-th. Each watered pumpkin grows by exactly 1. A new election follows every watering, so the size of the Head Pumpkin changes. Report the size of the Head Pumpkin after each watering Hagrid does.

Input

The input holds several test cases.

The first line of a test case has two integers NN and KK (1N,K600001 \le N, K \le 60000). NN is always odd.

The next line has NN integers AiA_i (1Ai1091 \le A_i \le 10^9), the initial sizes of the pumpkins.

Each of the next KK lines has two integers SiS_i and TiT_i (1SiTiN1 \le S_i \le T_i \le N), meaning that Hagrid watered every pumpkin numbered from SiS_i to TiT_i.

The sum of NN over all test cases is at most 60000, and the sum of KK over all test cases is at most 60000.

The last line of the input has two zeros. That line is not a test case and must not be processed.

Output

For each test case print KK lines. The ii-th of them holds the size of the Head Pumpkin right after the ii-th watering. Since NN is odd, that size is the (N+1)/2(N+1)/2-th smallest size in the row.