#include <bits/stdc++.h>
using namespace std;
int n, m;
struct tree {
  int l, r;
  int mn;
} T[4000010];
int a[1000010], x[1000010], y[1000010];
int findf(int xx) {
  int l = 1, r = y[0];
  while (l <= r) {
    int mid = l + r >> 1;
    if (y[mid] > xx)
      r = mid - 1;
    else if (y[mid] < xx)
      l = mid + 1;
    else
      return mid;
  }
}
void build(int l, int r, int p) {
  T[p].l = l;
  T[p].r = r;
  T[p].mn = 1000000000;
  if (l == r) return;
  int mid = l + r >> 1;
  build(l, mid, p << 1);
  build(mid + 1, r, p << 1 | 1);
}
void pushup(int p) { T[p].mn = min(T[p << 1].mn, T[p << 1 | 1].mn); }
void update(int x, int p, int c) {
  int ll = T[p].l, rr = T[p].r;
  if (ll == rr) {
    T[p].mn = c;
    return;
  }
  int mid = ll + rr >> 1;
  if (x <= mid)
    update(x, p << 1, c);
  else if (x > mid)
    update(x, p << 1 | 1, c);
  pushup(p);
}
int query(int l, int r, int p) {
  int ll = T[p].l, rr = T[p].r;
  if (ll == l && r == rr) return T[p].mn;
  int mid = ll + rr >> 1;
  if (r <= mid)
    return query(l, r, p << 1);
  else if (l > mid)
    return query(l, r, p << 1 | 1);
  else
    return min(query(l, mid, p << 1), query(mid + 1, r, p << 1 | 1));
}
struct node {
  int l, r, id;
} q[1000010];
int cmp(node x, node y) {
  if (x.r == y.r) return x.l > y.l;
  return x.r < y.r;
}
int last[1000010], ans[1000010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    x[++x[0]] = a[i];
  }
  sort(x + 1, x + 1 + x[0]);
  y[++y[0]] = x[1];
  for (int i = 2; i <= x[0]; i++) {
    if (x[i] != x[i - 1]) y[++y[0]] = x[i];
  }
  for (int i = 1; i <= n; i++) a[i] = findf(a[i]);
  build(1, n, 1);
  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, cmp);
  int now = 1;
  for (int i = 1; i <= m; i++) {
    while (now <= q[i].r) {
      if (last[a[now]]) {
        update(last[a[now]], 1, now - last[a[now]]);
      }
      last[a[now]] = now;
      now++;
    }
    ans[q[i].id] = query(q[i].l, q[i].r, 1);
  }
  for (int i = 1; i <= m; i++)
    printf("%d\n", ans[i] == 1000000000 ? -1 : ans[i]);
  return 0;
}
