Codeforces Round #416 (Div. 2) has been moved to start on 27.05.2017 09:05 (UTC).
×

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

D. Closest Equals

time limit per test

3 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou are given sequence *a*_{1}, *a*_{2}, ..., *a*_{n} and *m* queries *l*_{j}, *r*_{j} (1 ≤ *l*_{j} ≤ *r*_{j} ≤ *n*). For each query you need to print the minimum distance between such pair of elements *a*_{x} and *a*_{y} (*x* ≠ *y*), that:

- both indexes of the elements lie within range [
*l*_{j},*r*_{j}], that is,*l*_{j}≤*x*,*y*≤*r*_{j}; - the values of the elements are equal, that is
*a*_{x}=*a*_{y}.

The text above understands distance as |*x* - *y*|.

Input

The first line of the input contains a pair of integers *n*, *m* (1 ≤ *n*, *m* ≤ 5·10^{5}) — the length of the sequence and the number of queries, correspondingly.

The second line contains the sequence of integers *a*_{1}, *a*_{2}, ..., *a*_{n} ( - 10^{9} ≤ *a*_{i} ≤ 10^{9}).

Next *m* lines contain the queries, one per line. Each query is given by a pair of numbers *l*_{j}, *r*_{j} (1 ≤ *l*_{j} ≤ *r*_{j} ≤ *n*) — the indexes of the query range limits.

Output

Print *m* integers — the answers to each query. If there is no valid match for some query, please print -1 as an answer to this query.

Examples

Input

5 3

1 1 2 3 2

1 5

2 4

3 5

Output

1

-1

2

Input

6 5

1 2 1 3 2 3

4 6

1 3

2 5

2 4

1 6

Output

2

2

3

-1

2

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/26/2017 04:49:49 (p1).

Desktop version, switch to mobile version.
User lists

Name |
---|