#include <bits/stdc++.h>
using namespace std;
const int TSIZE = 1048576;
pair<int, int> t[2 * TSIZE + 3];
const pair<int, int> neutral = make_pair(0x3F3F3F3F, 0);
pair<int, int> operator*(const pair<int, int>& p1, const pair<int, int>& p2) {
  return make_pair(min(p1.first, p2.first), 0);
}
void update(int x, const pair<int, int>& val) {
  t[x + TSIZE] = val;
  for (int p = (x + TSIZE) / 2; p >= 1; p /= 2) {
    t[p] = t[2 * p] * t[2 * p + 1];
  }
}
pair<int, int> qrec(int v, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    return t[v];
  } else if (r < L || l > R) {
    return neutral;
  } else {
    int m = (l + r) / 2;
    return qrec(2 * v, l, m, L, R) * qrec(2 * v + 1, m + 1, r, L, R);
  }
}
pair<int, int> query(int l, int r) { return qrec(1, 0, TSIZE - 1, l, r); }
int n, m;
int a[500000 + 3];
unordered_map<int, int> prevl;
int leftD[500000 + 3];
int rightI[500000 + 3];
int qidx[500000 + 3];
int ql[500000 + 3];
int qr[500000 + 3];
int qans[500000 + 3];
bool comp(int a, int b) {
  if (ql[a] != ql[b]) {
    return ql[a] < ql[b];
  } else if (qr[a] != qr[b]) {
    return qr[a] < qr[b];
  } else {
    return a < b;
  }
}
int main(int argc, char* argv[]) {
  prevl.max_load_factor(0.75f);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  memset(leftD, 0x3F3F3F3F, sizeof(leftD));
  memset(rightI, 0x3F3F3F3F, sizeof(rightI));
  for (int i = 0; i < n; i++) {
    if (prevl.find(a[i]) != prevl.end()) {
      leftD[i] =
          ((prevl[a[i]] - i) < 0 ? -(prevl[a[i]] - i) : (prevl[a[i]] - i));
      rightI[prevl[a[i]]] = i;
    }
    prevl[a[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    update(i, make_pair(leftD[i], 0));
  }
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--;
    r--;
    ql[i] = l;
    qr[i] = r;
    qidx[i] = i;
  }
  sort(qidx, qidx + m, comp);
  int left = 0;
  for (int q = 0; q < m; q++) {
    int l = ql[qidx[q]];
    int r = qr[qidx[q]];
    while (left < l) {
      if (rightI[left] < 0x3F3F3F3F) {
        update(rightI[left], make_pair(0x3F3F3F3F, 0));
      }
      left++;
    }
    qans[qidx[q]] = query(l, r).first;
  }
  for (int q = 0; q < m; q++) {
    if (qans[q] < 0x3F3F3F3F) {
      printf("%d\n", qans[q]);
    } else {
      printf("-1\n");
    }
  }
  return 0;
}
