#include <bits/stdc++.h>
using namespace std;
int n, m, tree[500010 << 2], a[500010], b[500010], lef[500010], last[500010],
    ans[500010], size;
struct Q {
  int l, r, id;
} q[500010];
inline void read(int &x) {
  char s = getchar();
  int f = 1;
  x = 0;
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') x = (x << 3) + (x << 1) + s - '0', s = getchar();
  x *= f;
}
inline bool cmp1(const Q &x, const Q &y) { return x.r < y.r; }
inline void modify(int x, int val, int l, int r, int o) {
  int mid = (l + r) >> 1;
  if (l == r) {
    tree[o] = val;
    return;
  }
  if (x <= mid)
    modify(x, val, l, mid, o << 1);
  else
    modify(x, val, mid + 1, r, o << 1 | 1);
  tree[o] = min(tree[o << 1], tree[o << 1 | 1]);
}
inline int query(int x, int y, int l, int r, int o) {
  int mid = (l + r) >> 1, ans = 0x7fffffff;
  if (x <= l && r <= y) return tree[o];
  if (x <= mid) ans = min(ans, query(x, y, l, mid, o << 1));
  if (y > mid) ans = min(ans, query(x, y, mid + 1, r, o << 1 | 1));
  return ans;
}
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) read(a[i]), b[i] = a[i];
  sort(b + 1, b + n + 1);
  size = unique(b + 1, b + n + 1) - b - 1;
  for (int i = 1; i <= n; i++) {
    a[i] = lower_bound(b + 1, b + size + 1, a[i]) - b;
    lef[i] = last[a[i]];
    last[a[i]] = i;
  }
  for (int i = 1; i <= m; i++) read(q[i].l), read(q[i].r), q[i].id = i;
  sort(q + 1, q + m + 1, cmp1);
  memset(tree, 0x7f, sizeof(tree));
  int i = 1, j = 1;
  while (i <= n && j <= m) {
    if (lef[i]) modify(lef[i], i - lef[i], 1, n, 1);
    while (i == q[j].r && j <= m)
      ans[q[j].id] = query(q[j].l, q[j].r, 1, n, 1), j++;
    i++;
  }
  for (int i = 1; i <= m; i++)
    ans[i] == 2139062143 ? printf("-1\n") : printf("%d\n", ans[i]);
  return 0;
}
