#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
int a[500105], l[500105], ans[500105];
void init() {
  unordered_map<int, int> pos;
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    if (pos.find(a[i]) != pos.end()) l[i] = pos[a[i]];
    pos[a[i]] = i;
  }
}
struct qy {
  int l, r, id;
  bool operator<(const qy &o) const { return r < o.r; }
} q[500105];
const int MN = (1 << 20) + 5;
int M, T[MN];
void update(int l, int v) {
  l += M;
  T[l] = v;
  while (l > 1) {
    T[l >> 1] = min(T[l ^ 1], T[l]);
    l >>= 1;
  }
}
int qy(int l, int r) {
  int ans = (1 << 30);
  for (l = l + M - 1, r = r + M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
    if (~l & 1) ans = min(ans, T[l ^ 1]);
    if (r & 1) ans = min(ans, T[r ^ 1]);
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", a + i);
  init();
  for (int(i) = 0; (i) < (int)(m); (i)++) {
    scanf("%d%d", &q[i].l, &q[i].r);
    q[i].id = i;
  }
  sort(q, q + m);
  for (M = 1; n + 2 > M; M <<= 1)
    ;
  for (int(i) = 0; (i) < (int)(MN); (i)++) T[i] = (1 << 30);
  int x = 0;
  for (int(i) = 0; (i) < (int)(m); (i)++) {
    while (x < q[i].r) {
      x++;
      if (l[x] > 0) update(l[x], x - l[x]);
    }
    ans[q[i].id] = qy(q[i].l, q[i].r);
  }
  for (int(i) = 0; (i) < (int)(m); (i)++)
    printf("%d\n", ans[i] == (1 << 30) ? -1 : ans[i]);
  return 0;
}
