#include <bits/stdc++.h>
int read() {
  int x = 0, minus = 0;
  char ch;
  while (!isdigit(ch = getchar())) minus |= (ch == '-');
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return minus ? -x : x;
}
const int N = 5e5 + 10, INF = 1e6;
int n, T, c[N], sum[N << 2], ls[N << 2], rs[N << 2], las[N], ans[N];
struct A {
  int num, id;
} a[N];
struct node {
  int l, r, id;
} Q[N];
int min(int x, int y) { return x < y ? x : y; }
bool cmp1(A x, A y) { return x.num < y.num; }
bool cmp2(node x, node y) { return x.r < y.r; }
void build(int k, int l, int r) {
  ls[k] = l, rs[k] = r;
  if (l == r) {
    sum[k] = INF;
    return;
  }
  int mid = (l + r) >> 1;
  build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r);
  sum[k] = min(sum[k << 1], sum[k << 1 | 1]);
}
void update(int k, int x, int v) {
  if (ls[k] == rs[k]) {
    sum[k] = v;
    return;
  }
  if (x <= rs[k << 1])
    update(k << 1, x, v);
  else
    update(k << 1 | 1, x, v);
  sum[k] = min(sum[k << 1], sum[k << 1 | 1]);
}
int query(int k, int x, int y) {
  if (ls[k] >= x && rs[k] <= y) return sum[k];
  if (y <= rs[k << 1]) return query(k << 1, x, y);
  if (x >= ls[k << 1 | 1]) return query(k << 1 | 1, x, y);
  return min(query(k << 1, x, y), query(k << 1 | 1, x, y));
}
signed main() {
  n = read(), T = read();
  for (register int i = 1; i <= n; ++i) a[i] = (A){read(), i};
  std::sort(a + 1, a + 1 + n, cmp1);
  for (register int i = 1, tp = 0; i <= n; ++i)
    c[a[i].id] = (tp += (a[i - 1].num != a[i].num));
  for (register int i = 1, x, y; i <= T; ++i)
    x = read(), y = read(), Q[i] = (node){x, y, i};
  std::sort(Q + 1, Q + 1 + T, cmp2);
  build(1, 1, n);
  for (register int i = 1, R = 1; i <= T; ++i) {
    while (R <= Q[i].r) {
      if (las[c[R]]) update(1, las[c[R]], R - las[c[R]]);
      las[c[R]] = R;
      ++R;
    }
    int tmp = query(1, Q[i].l, Q[i].r);
    if (tmp == INF)
      ans[Q[i].id] = -1;
    else
      ans[Q[i].id] = tmp;
  }
  for (register int i = 1; i <= T; ++i) printf("%d\n", ans[i]);
  return 0;
}
