You have a sequence a of length n and you want to answer q queries determined by 2 integers l and r. You take all numbers present in subsequence (al,al+1,…,ar), let them be b1,b2,…,bt and number of occurrenses of each number in this subsequence be c1,c2,…,ct respectively. The answer for per query is equal to min|ci−cj| for 1≤i<j≤t or 1 if t=1.
Input
The first line contains 2 integers - n and q (1≤n,q≤100000).
The second line contains n numbers - a1,a2,…,an (1≤ai≤109).
Each of the next q lines contains 2 integers - ui,vi (1≤ui,vi≤n).
You will need to answer the queries online so the information is encoded, if the answer for (i−1)th query is last (initially last=0) then the ith query is :
li=((ui+last)modn)+1
ri=((vi+last)modn)+1
Note that "last" can be -1 in some cases.
Output
Output q lines, the ith line contains the answer for the ith query.
The queries are (2,5),(1,1),(2,4),(1,6) in this order.
For the query (1,6), b=(1,2,3) and c=(1,2,3) so the answer 1.
For the query (1,1), t=1 implies that the answer is 1.