#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e5, inf = 0x7f7f7f7f;
map<int, int> last;
int n, m, a[N + 10], ans[N + 10], nxt[N + 10], val[N + 10], seg[N * 4 + 10];
inline void input(int &x) {
  x = 0;
  bool flag = false;
  char ch = getchar();
  while (!(ch >= '0' && ch <= '9' || ch == '-')) ch = getchar();
  if (ch == '-') flag = true, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  if (flag) x = -x;
}
inline void output(int x) {
  if (!x) {
    puts("0");
    return;
  }
  if (x == inf) {
    puts("-1");
    return;
  }
  int digit[20], len = 0;
  while (x) digit[len++] = x % 10, x /= 10;
  for (int(i) = (len - 1); (i) >= (0); --(i)) putchar(digit[i] + '0');
  putchar('\n');
}
struct Query {
  int l, r, id;
  inline void read(int _id) {
    input(l);
    input(r);
    id = _id;
  }
} q[N + 10];
inline bool cmp(const Query &a, const Query &b) { return a.l < b.l; }
inline void update(int k) { seg[k] = min(seg[k << 1], seg[k << 1 | 1]); }
void build(int k, int l, int r) {
  if (l == r) {
    seg[k] = val[l];
    return;
  }
  int mid = l + r >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
  update(k);
}
int query(int k, int lc, int rc, int l, int r) {
  if (l == lc && r == rc) return seg[k];
  int mid = lc + rc >> 1;
  if (r <= mid) return query(k << 1, lc, mid, l, r);
  if (l > mid) return query(k << 1 | 1, mid + 1, rc, l, r);
  return min(query(k << 1, lc, mid, l, mid),
             query(k << 1 | 1, mid + 1, rc, mid + 1, r));
}
void modify(int k, int lc, int rc, int p, int d) {
  if (lc == rc) {
    seg[k] = d;
    return;
  }
  int mid = lc + rc >> 1;
  if (p <= mid)
    modify(k << 1, lc, mid, p, d);
  else
    modify(k << 1 | 1, mid + 1, rc, p, d);
  update(k);
}
int main() {
  input(n);
  input(m);
  for (int(i) = (1); (i) <= (n); ++(i)) input(a[i]);
  for (int(i) = (1); (i) <= (m); ++(i)) q[i].read(i);
  sort(q + 1, q + m + 1, cmp);
  for (int(i) = (n); (i) >= (1); --(i)) {
    int &x = last[a[i]];
    if (x) nxt[i] = x;
    x = i;
  }
  last.clear();
  for (int(i) = (1); (i) <= (n); ++(i)) {
    int &x = last[a[i]];
    if (x)
      val[i] = i - x;
    else
      val[i] = inf;
    x = i;
  }
  build(1, 1, n);
  for (int i = 1, j = 1, last = 1; i <= m; i = j) {
    for (int(k) = (last); (k) <= (q[i].l - 1); ++(k))
      if (nxt[k]) modify(1, 1, n, nxt[k], inf);
    last = q[i].l;
    while (q[i].l == q[j].l && j <= m) j++;
    for (int(k) = (i); (k) <= (j - 1); ++(k))
      ans[q[k].id] = query(1, 1, n, q[k].l, q[k].r);
  }
  for (int(i) = (1); (i) <= (m); ++(i)) output(ans[i]);
  return 0;
}
