Couriers

No attempts yetTime limit3sMemory limit512 MB

Problem

Byteasar works for BAJ, a company that sells computer games. BAJ has contracts with several courier companies, and they deliver the games BAJ sells to its customers. Byteasar is checking how those contracts are being kept. He has a log of the packages BAJ shipped, in chronological order, with the number of the courier company that delivered each package.

If one courier company delivered more than half of the packages shipped during some period, we say that it dominated that period. Byteasar wants to know, for each period he is interested in, whether a courier company dominated it, and which one.

Write a program that finds the dominating courier company for each period, or reports that there is none.

Input

The first line contains two integers nn and mm, separated by a single space (1n,m5000001 \le n, m \le 500\,000): the number of packages BAJ shipped and the number of periods to examine. The courier companies are numbered from 11 to at most nn.

The second line contains nn integers p1,p2,,pnp_1, p_2, \dots, p_n, separated by single spaces (1pin1 \le p_i \le n). The value pip_i is the number of the courier company that delivered the ii-th package in shipment order.

Each of the next mm lines describes one period with two integers aa and bb, separated by a single space (1abn1 \le a \le b \le n). The period runs from the aa-th shipped package to the bb-th shipped package, both included.

Output

Print one line per period, mm lines in total. Each line holds the number of the courier company that dominated the corresponding period, or 00 if no company dominated it.