You are given sequence *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> and *m* queries *l*<sub class="lower-index">*j*</sub>, *r*<sub class="lower-index">*j*</sub> (1 ≤ *l*<sub class="lower-index">*j*</sub> ≤ *r*<sub class="lower-index">*j*</sub> ≤ *n*). For each query you need to print the minimum distance between such pair of elements *a*<sub class="lower-index">*x*</sub> and *a*<sub class="lower-index">*y*</sub> (*x* ≠ *y*), that:
 -  both indexes of the elements lie within range [*l*<sub class="lower-index">*j*</sub>, *r*<sub class="lower-index">*j*</sub>], that is, *l*<sub class="lower-index">*j*</sub> ≤ *x*, *y* ≤ *r*<sub class="lower-index">*j*</sub>; -  the values of the elements are equal, that is *a*<sub class="lower-index">*x*</sub> = *a*<sub class="lower-index">*y*</sub>. 
The text above understands distance as |*x* - *y*|.
The first line of the input contains a pair of integers *n*, *m* (1 ≤ *n*, *m* ≤ 5·10<sup class="upper-index">5</sup>) — the length of the sequence and the number of queries, correspondingly. 

The second line contains the sequence of integers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> ( - 10<sup class="upper-index">9</sup> ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>). 

Next *m* lines contain the queries, one per line. Each query is given by a pair of numbers *l*<sub class="lower-index">*j*</sub>, *r*<sub class="lower-index">*j*</sub> (1 ≤ *l*<sub class="lower-index">*j*</sub> ≤ *r*<sub class="lower-index">*j*</sub> ≤ *n*) — the indexes of the query range limits.
__author__ = 'ruckus'
import threading
def Find(i, minimum, req):
    j = a[req[0]-1:req[1]]
    for k in range(len(j)-1):
        for l in range(k+1, len(j)):
            if l-k >= minimum[i]:
                break
            if j[k] == j[l]:
                minimum[i] = l-k
                break
        if minimum[i] == 1:
            return
'''in_f = open('1.txt')'''
'n, m = map(int, in_f.readline().split())'
n, m = map(int, input().split())
'a = list(map(int, in_f.readline().split()))'
a = list(map(int, input().split()))
minimum = [500000 for i in range(m)]
thr = []
for i in range(m):
    'req = list(map(int, in_f.readline().split()))'
    req = list(map(int, input().split()))
    thr.append(threading.Thread(target=Find, args=(i, minimum, req)))
    thr[i].start()
map(lambda x: x.join(), thr)
minimum = list(map(lambda x:str(-1 if x==500000 else x), minimum))
print('\n'.join(minimum))