Smallest Unpayable Amount

For each query interval, find the smallest positive amount that cannot be formed as a subset sum of the coins in that interval.

Hard9GreedySortingSegment treeBinary searchNo attempts yetTime limit4sMemory limit512 MB

Problem

Boris has collected nn coins. He laid them out in a row, and the ii-th coin in the row has value aia_i.

Boris is about to leave on a trip, but he is short of time, so he plans to take one continuous segment of adjacent coins from the row.

Boris wants to answer several queries. For each query he wants to know the smallest amount he cannot pay without receiving change, given that he takes the coins from position lil_i to position rir_i. Formally, find the smallest positive integer zz such that no choice of coins from position lil_i to position rir_i has values summing to zz.

Input

The first line contains the number of coins nn and the number of queries mm (1n,m1500001 \le n, m \le 150000). The second line contains nn integers aia_i, the values of the coins (1ai1091 \le a_i \le 10^9).

Each of the next mm lines contains two integers lil_i and rir_i (1lirin1 \le l_i \le r_i \le n), the first and the last position of the segment Boris takes.

Output

For each query print one integer on its own line: the smallest amount that cannot be paid without change using the coins from position lil_i to position rir_i.