#include <bits/stdc++.h>
using namespace std;
const int MX = 5e5 + 5;
const int INF = 0x3f3f3f3f;
int MIN[MX << 2];
void push_up(int rt) { MIN[rt] = min(MIN[rt << 1], MIN[rt << 1 | 1]); }
void update(int x, int d, int l, int r, int rt) {
  if (l == r) {
    MIN[rt] = min(MIN[rt], d);
    return;
  }
  int m = (l + r) >> 1;
  if (x <= m)
    update(x, d, l, m, rt << 1);
  else
    update(x, d, m + 1, r, rt << 1 | 1);
  push_up(rt);
}
int query(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) {
    return MIN[rt];
  }
  int m = (l + r) >> 1, ret = INF;
  if (L <= m) ret = min(ret, query(L, R, l, m, rt << 1));
  if (R > m) ret = min(ret, query(L, R, m + 1, r, rt << 1 | 1));
  return ret;
}
struct Que {
  int l, r, id;
  bool operator<(const Que &P) const { return r < P.r; }
} Q[MX];
int pre[MX], A[MX], B[MX], ans[MX];
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    memset(MIN, INF, sizeof(MIN));
    memset(pre, 0, sizeof(pre));
    for (int i = 1; i <= n; i++) {
      scanf("%d", &B[i]);
      A[i] = B[i];
    }
    sort(B + 1, B + 1 + n);
    int rear = unique(B + 1, B + 1 + n) - B - 1;
    for (int i = 1; i <= n; i++) {
      A[i] = lower_bound(B + 1, B + 1 + n, A[i]) - B;
    }
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &Q[i].l, &Q[i].r);
      Q[i].id = i;
    }
    sort(Q + 1, Q + 1 + m);
    for (int i = 1, c = 1; i <= n; i++) {
      if (pre[A[i]]) update(pre[A[i]], i - pre[A[i]], 1, n, 1);
      while (c <= m && i == Q[c].r) {
        int Min = query(Q[c].l, Q[c].r, 1, n, 1);
        ans[Q[c++].id] = Min == INF ? -1 : Min;
      }
      pre[A[i]] = i;
    }
    for (int i = 1; i <= m; i++) {
      printf("%d\n", ans[i]);
    }
  }
  return 0;
}
