Stone Games
时间限制:C/C++/Rust/Pascal 4秒,其他语言8秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
64bit IO Format: %lld

题目描述


There are  piles of stones, the -th of which contains  stones. The tiles are numbered from  to . Rika and Satoko are playing a game on it.

During each round of the game, Rika chooses some piles from all  piles. Let denote the set of all chosen piles as . Satoko then writes a non-negative integer . If Rika takes some piles from  with the number of stones among all the taken piles equal to , she wins the game, while otherwise (Rika cannot find such piles) Satoko wins the game. Note that each tile can be taken at most once during a round, and it is possible that Rika does not pick up any tile (when ).

There are  rounds of game in total, and for the -th round of game Rika will let  be the set of all piles with index between  and . For each round, Satoko wonders the minimum integer  she can write to win the game. As you are a master of programming, it is your turn to solve the problem!



输入描述:

The first line of input contains two integers  and , where  is the number of tiles and  is the number of the rounds of the games.

The second line contains  integers , the -th of which, , indicates the number of stones in the tile with index .

Satoko wants you to compute the answers immediately after Rika chooses the interval, so she uses the following method to encrypt the input. The -th of the next  lines contains two integers . The chosen index range for the -th round, , can be computed by the following formula:


where  denotes the answer for the -th round of the game (and thus  is the answer for the previous round). You can assume that . It is clear that under the given constraints,  holds.

输出描述:

Output  lines, the -th of which contains a single integer , denoting the minimum integer  Satoko can choose to win the -th round of the game.
示例1

输入

复制
5 5
1 4 2 1 6
1 3
2 1
2 4
1 4
3 4

输出

复制
8
15
4
9
4

说明

In the example above, the actual query intervals are  and .