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.
import sys
from collections import *
from itertools import *
from math import *
from array import *
from functools import lru_cache
import heapq
import bisect
import random
import io, os

if sys.hexversion == 50924784:
    sys.stdin = open('cfinput.txt')

# input = sys.stdin.readline
# input_int = sys.stdin.buffer.readline
# RI = lambda: map(int, input_int().split())
# RS = lambda: input().strip().split()
# RILST = lambda: list(RI())

RI = lambda: map(int, sys.stdin.buffer.readline().split())
RS = lambda: sys.stdin.readline().strip().split()
RILST = lambda: list(RI())

MOD = 10 ** 9 + 7
"""https://codeforces.com/problemset/problem/522/D

输入 n(2≤n≤2e5) 和 m(1≤m≤2e5)；然后输入一个长为 n 的数组 a(-1e9≤a[i]≤1e9)，数组下标从 1 开始；然后输入 m 个询问，每个询问表示一个数组 a 内的闭区间 [L,R] (1≤L≤R≤n)。

对每个询问，输出区间内的相同元素下标之间的最小差值。如果区间内不存在相同元素，输出 -1。

输入
5 3
1 1 2 3 2
1 5
2 4
3 5
输出
1
-1
2

输入
6 5
1 2 1 3 2 3
4 6
1 3
2 5
2 4
1 6
输出
2
2
3
-1
2
"""


class IntervalTree:
    def __init__(self, size, nums=None):
        self.size = size
        self.nums = nums
        self.interval_tree = [inf] * (size * 4)

    def update_point(self, p, l, r, index, val):
        if index < l or r < index:
            return
        interval_tree = self.interval_tree
        interval_tree[p] = min(interval_tree[p], val)
        if l == r:
            return
        mid = (l + r) // 2
        if index <= mid:
            self.update_point(p * 2, l, mid, index, val)
        else:
            self.update_point(p * 2 + 1, mid + 1, r, index, val)

    def query(self, p, l, r, x, y):
        """
        查找x,y区间的最大值        """

        if y < l or r < x:
            return 0
        if x <= l and r <= y:
            return self.interval_tree[p]

        mid = (l + r) // 2
        s = inf
        if x <= mid:
            s = min(s, self.query(p * 2, l, mid, x, y))
        if mid < y:
            s = min(s, self.query(p * 2 + 1, mid + 1, r, x, y))
        return s



# 	 ms
def solve(n, m, a, q):
    a = [0] + a
    q = sorted([(l, r, i) for i, (l, r) in enumerate(q)], key=lambda x: x[1])
    tree = IntervalTree(n+1)
    pre = {}
    j = 1
    ans = [-1] * m
    for l, r, i in q:
        while j <= r:
            v = a[j]
            if v in pre:
                idx = pre[v]
                d = j - idx
                # cur = tree.query(1, 1, n + 1, idx, idx)
                # if cur > d:
                #     tree.update_point(1, 1, n + 1, idx, d)
                tree.update_point(1, 1, n + 1, idx, d)

            pre[v] = j
            j += 1
        cur = tree.query(1, 1, n + 1, l, r)
        if cur < inf:
            ans[i] = cur

    # print(ans)
    for i in ans:
        print(i)

if __name__ == '__main__':
    n, m = RI()
    a = RILST()
    q = []
    for _ in range(m):
        q.append(RILST())

    solve(n, m, a, q)
