#include <bits/stdc++.h>
using namespace std;
int n, q;
int v[500005];
int ans[500005];
int T[4 * 500005];
pair<int, pair<int, int> > p[500005];
map<int, int> M;
void build(int pos, int val, int l, int r, int node) {
  if (l == r) {
    T[node] = val;
    return;
  }
  if (pos <= (l + r) / 2)
    build(pos, val, l, (l + r) / 2, node * 2);
  else
    build(pos, val, (l + r) / 2 + 1, r, node * 2 + 1);
  T[node] = min(T[node * 2], T[node * 2 + 1]);
}
int tap(int a, int b, int l, int r, int node) {
  if (a > r || b < l) return 1000000007;
  if (a <= l && b >= r) return T[node];
  return min(tap(a, b, l, (l + r) / 2, node * 2),
             tap(a, b, (l + r) / 2 + 1, r, node * 2 + 1));
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
  fill(T, T + 4 * 500005, 1000000007);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &p[i].second.first, &p[i].first);
    p[i].second.second = i;
  }
  sort(p + 1, p + 1 + q);
  int now = 1;
  for (int i = 1; i <= n; i++) {
    int pos = M[v[i]];
    if (pos) build(pos, i - pos, 1, n, 1);
    M[v[i]] = i;
    while (p[now].first == i)
      ans[p[now].second.second] =
          tap(p[now].second.first, p[now].first, 1, n, 1),
      now++;
  }
  for (int i = 1; i <= q; i++)
    printf("%d\n", (ans[i] == 1000000007 ? -1 : ans[i]));
}
