#include <bits/stdc++.h>
using namespace std;
const int N = 500010, INF = 0x3f3f3f3f;
struct seg {
  int l, r;
  int id;
  bool operator<(const seg &A) const {
    if (r == A.r) return l < A.l;
    return r < A.r;
  }
} qry[N];
struct Node {
  int l, r;
  int minv;
} tr[N * 4];
int alls[N], cnt;
int tot;
int n, m;
int ans[N];
int a[N];
int last[N];
int find(int x) { return lower_bound(alls + 1, alls + 1 + cnt, x) - alls; }
void pushup(int u) { tr[u].minv = min(tr[u << 1].minv, tr[u << 1 | 1].minv); }
void build(int u, int l, int r) {
  if (l == r) {
    tr[u] = {l, r, INF};
    return;
  }
  tr[u] = {l, r};
  int mid = l + r >> 1;
  build(u << 1, l, mid);
  build(u << 1 | 1, mid + 1, r);
  pushup(u);
}
void modify(int u, int x, int k) {
  if (tr[u].l == x && tr[u].r == x) {
    tr[u].minv = k;
    return;
  }
  int mid = (tr[u].l + tr[u].r) >> 1;
  if (x <= mid)
    modify(u << 1, x, k);
  else
    modify(u << 1 | 1, x, k);
  pushup(u);
}
int query(int u, int l, int r) {
  if (tr[u].l >= l && tr[u].r <= r) return tr[u].minv;
  int mid = (tr[u].l + tr[u].r) >> 1;
  int res = INF;
  if (l <= mid) res = min(res, query(u << 1, l, r));
  if (r > mid) res = min(res, query(u << 1 | 1, l, r));
  return res;
}
void solve() {
  scanf("%d%d", &n, &m);
  memset(ans, -1, sizeof ans);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    alls[++cnt] = a[i];
  }
  sort(alls + 1, alls + 1 + n);
  cnt = unique(alls + 1, alls + 1 + n) - alls - 1;
  for (int i = 1; i <= n; i++) a[i] = find(a[i]);
  for (int i = 1; i <= cnt; i++) last[i] = -1;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    qry[i] = seg({x, y, i});
  }
  sort(qry + 1, qry + 1 + m);
  build(1, 1, n);
  for (int i = 1, j = 1; i <= n; i++) {
    if (last[a[i]] != -1) modify(1, last[a[i]], i - last[a[i]]);
    last[a[i]] = i;
    while (j <= m && qry[j].r == i) {
      ans[qry[j].id] = query(1, qry[j].l, qry[j].r);
      j++;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i] == INF ? -1 : ans[i]);
}
int main() {
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
