#include <bits/stdc++.h>
using namespace std;
struct Range {
  int l, r, d;
  Range(int l = 0, int r = 0, int d = 0) : l(l), r(r), d(d) {}
};
const int MAXN = 5e5 + 20;
int n, m, a[MAXN], rpt = 0, lb[MAXN], st[MAXN][22], ls[MAXN], rs[MAXN];
map<int, int> pos;
Range rg[MAXN];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (pos.count(a[i])) {
      int prev = pos[a[i]];
      pos[a[i]] = i;
      if (!rpt)
        rg[++rpt] = Range(prev, i, i - prev);
      else if (rg[rpt].l >= prev)
        continue;
      else
        rg[++rpt] = Range(prev, i, i - prev);
    } else
      pos[a[i]] = i;
  }
  lb[0] = -1;
  for (int i = 1; i <= rpt; i++) {
    lb[i] = lb[i / 2] + 1;
    st[i][0] = rg[i].d;
  }
  for (int j = 1; (1 << j) <= rpt; j++)
    for (int i = 1; i + (1 << j) - 1 <= rpt; i++)
      st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
  for (int i = 1; i <= rpt; i++) {
    ls[i] = rg[i].l;
    rs[i] = rg[i].r;
  }
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    l = lower_bound(ls + 1, ls + rpt + 1, l) - ls;
    r = upper_bound(rs + 1, rs + rpt + 1, r) - rs - 1;
    if (r < l)
      printf("-1\n");
    else
      printf("%d\n", min(st[l][lb[r - l + 1]],
                         st[r - (1 << lb[r - l + 1]) + 1][lb[r - l + 1]]));
  }
}
