#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long INF = 1LL << 60;
const int MaxN = 500003;
int n, m;
struct Segtree {
  int l, r;
  int MIN;
} tree[(MaxN << 2) + 5];
struct Query {
  int l, r;
  int pos, ans;
  friend bool operator<(const Query A, const Query B) {
    if (A.l == B.l) return A.r < B.r;
    return A.l < B.l;
  }
} Q[MaxN + 5];
int a[MaxN + 5], b[MaxN + 5], gap[MaxN + 5];
map<int, int> back;
void push_up(int rt) {
  tree[rt].MIN = min(tree[rt << 1].MIN, tree[rt << 1 | 1].MIN);
}
void Build(int rt, int l, int r) {
  tree[rt].l = l;
  tree[rt].r = r;
  if (l == r) {
    tree[rt].MIN = b[l];
    return;
  }
  int mid = (l + r) >> 1;
  Build(rt << 1, l, mid);
  Build(rt << 1 | 1, mid + 1, r);
  push_up(rt);
}
void update(int rt, int pos, int val) {
  if (tree[rt].l == tree[rt].r) {
    tree[rt].MIN = val;
    return;
  }
  int mid = (tree[rt].l + tree[rt].r) >> 1;
  if (pos <= mid)
    update(rt << 1, pos, val);
  else
    update(rt << 1 | 1, pos, val);
  push_up(rt);
}
int query(int rt, int L, int R) {
  if (tree[rt].l > R || tree[rt].r < L) return inf;
  if (L <= tree[rt].l && tree[rt].r <= R) return tree[rt].MIN;
  int a = query(rt << 1, L, R);
  int b = query(rt << 1 | 1, L, R);
  return min(a, b);
}
bool cmpp(Query A, Query B) { return A.pos < B.pos; }
int main() {
  while (scanf("%d %d", &n, &m) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    back.clear();
    for (int i = n; i >= 1; i--) {
      int tmp = back[a[i]];
      if (tmp)
        gap[i] = tmp - i, b[tmp] = tmp - i;
      else
        gap[i] = inf;
      back[a[i]] = i;
    }
    for (int i = 1; i <= n; i++)
      if (b[i] == 0) b[i] = inf;
    for (int i = 1; i <= m; i++) {
      scanf("%d %d", &Q[i].l, &Q[i].r);
      Q[i].pos = i;
    }
    sort(Q + 1, Q + m + 1);
    Build(1, 1, n);
    int now = 1;
    for (int i = 1; i <= m; i++) {
      while (now < Q[i].l && now <= n) {
        if (gap[now] != inf) update(1, now + gap[now], inf);
        now++;
      }
      int res = query(1, Q[i].l, Q[i].r);
      if (res == inf)
        Q[i].ans = -1;
      else
        Q[i].ans = res;
    }
    sort(Q + 1, Q + m + 1, cmpp);
    for (int i = 1; i <= m; i++) printf("%d\n", Q[i].ans);
  }
  return 0;
}
