#include <bits/stdc++.h>
using namespace std;
const int N = 500500;
inline int read() {
  char ch;
  int f = 1;
  while ((ch = getchar()) < '0' || ch > '9')
    if (ch == '-') f = -1;
  int res = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0';
  return res * f;
}
struct que {
  int l, r, id;
} q[N];
bool operator<(que a, que b) { return a.l > b.l; }
int a[N], ans[N], px[N], mx, h[N], n;
struct Tree {
  int d[N];
  int lowbit(int x) { return x & -x; }
  void upt(int x, int v) {
    for (int i = x; i <= n; i += lowbit(i)) d[i] = min(d[i], v);
  }
  int qry(int x) {
    int res = n;
    for (int i = x; i; i -= lowbit(i)) res = min(d[i], res);
    return res;
  }
} T;
int main() {
  int m, l, r;
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) T.d[i] = n;
  for (int i = 1; i <= n; i++) px[i] = a[i] = read();
  sort(px + 1, px + 1 + n);
  mx = unique(px + 1, px + 1 + n) - px - 1;
  for (int i = 1; i <= n; i++)
    a[i] = lower_bound(px + 1, px + 1 + mx, a[i]) - px;
  for (int i = 1; i <= m; i++) {
    l = read();
    r = read();
    q[i] = (que){l, r, i};
  }
  sort(q + 1, q + 1 + m);
  l = n;
  for (int i = 1; i <= m; i++) {
    while (l >= q[i].l) {
      if (h[a[l]]) T.upt(h[a[l]], h[a[l]] - l);
      h[a[l]] = l;
      l--;
    }
    ans[q[i].id] = T.qry(q[i].r);
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i] == n ? -1 : ans[i]);
  return 0;
}
