#include <bits/stdc++.h>
using namespace std;
const int MaxN = 5e5;
const int INF = 1 << 30;
int tree[4 * MaxN + 5];
int pre[MaxN + 5], a[MaxN + 5];
int ans[MaxN + 5], marry[MaxN + 5];
int n, q;
struct node {
  int l, r, pos;
} p[MaxN + 5];
bool cmp(node a, node b) { return a.l < b.l; }
void pushup(int rt) { tree[rt] = min(tree[rt << 1], tree[rt << 1 | 1]); }
int query(int L, int R, int l, int r, int rt) {
  if (L <= l && R >= r) {
    return tree[rt];
  }
  int mid = (l + r) >> 1;
  int ans = INF;
  if (L <= mid) ans = min(ans, query(L, R, l, mid, rt << 1));
  if (R > mid) ans = min(ans, query(L, R, mid + 1, r, rt << 1 | 1));
  return ans;
}
void update(int p, int c, int l, int r, int rt) {
  if (l == r) {
    tree[rt] = c;
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    update(p, c, l, mid, rt << 1);
  else
    update(p, c, mid + 1, r, rt << 1 | 1);
  pushup(rt);
}
int main() {
  while (~scanf("%d %d", &n, &q)) {
    map<int, int> s;
    memset(marry, -1, sizeof(marry));
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) {
      if (i == 1)
        pre[i] = INF;
      else {
        if (s[a[i]] == 0)
          pre[i] = INF;
        else {
          pre[i] = s[a[i]];
          marry[s[a[i]]] = i;
        }
      }
      s[a[i]] = i;
      if (pre[i] == INF)
        update(i, pre[i], 1, n, 1);
      else
        update(i, i - pre[i], 1, n, 1);
    }
    for (int i = 1; i <= q; i++) scanf("%d %d", &p[i].l, &p[i].r), p[i].pos = i;
    sort(p + 1, p + q + 1, cmp);
    int now = 1;
    for (int i = 1; i <= q; i++) {
      if (p[i].l > now) {
        for (int j = now; j < p[i].l; j++) {
          update(marry[j], INF, 1, n, 1);
          now++;
        }
      }
      ans[p[i].pos] = query(1, p[i].r, 1, n, 1);
      if (ans[p[i].pos] == INF) ans[p[i].pos] = -1;
    }
    for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
