Best Student

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

문제

The SY School selects a best student every day. Given a list of the best students for nn days, the school wants to know a student who is most often selected as the best student during a period \[S,E]\[S, E] of days from SS to EE. The school plans to award for the student with a gift.

Given a list of best students for nn consecutive days and qq queries (S_1,E_1),,(S_q,E_q)\\{(S\_1, E\_1), \dots, (S\_q, E\_q)\\}, write a program to find the best student to be selected most often during the period \[S_i,E_i]\[S\_i, E\_i] for each query (S_i,E_i)(S\_i, E\_i).

입력

Your program is to read from standard input. The input starts with a line containing two integers, nn and qq, representing the number of days and the number of queries, respectively, where 1n 100,0001 \le n \le 100,000 and 1q100,0001 \le q \le 100,000. Students have unique id numbers between 11 and 10910^9. The next line consists of nn positive integers representing nn id numbers for best students, ordered from day 11 to day nn. Each of the following qq lines consists of two positive integers, S_iS\_i and E_iE\_i, that represent a query (S_i,E_i)(S\_i, E\_i), where \[S_i,E_i]\[S\_i, E\_i] is the period of days from S_iS\_i to E_iE\_i . Note that 1S_iE_in1 \le S\_i \le E\_i \le n for i=1,,qi = 1, \dots, q.

출력

Your program is to write to standard output. Print exactly qq lines. The ii-th line should contain the id number of the student selected most often as best student during the ii-th period \[S_i,E_i]\[S\_i, E\_i]. When there are more than one such students, the program should print the largest one among their id numbers.