#include <bits/stdc++.h>
using namespace std;
int nxt[1048576 / 2], tr[1048576];
void build(int t, int l, int r) {
  tr[t] = 1048576;
  if (l == r) return;
  build(2 * t, l, (l + r) / 2);
  build(2 * t + 1, (l + r) / 2 + 1, r);
}
void add(int t, int l, int r, int x) {
  if (r < x || l > x) return;
  if (l == r) {
    tr[t] = nxt[l];
    return;
  }
  add(2 * t, l, (l + r) / 2, x);
  add(2 * t + 1, (l + r) / 2 + 1, r, x);
  tr[t] = min(tr[2 * t], tr[2 * t + 1]);
}
int L, R, ans;
void get_min(int t, int l, int r) {
  if (R < l || r < L) return;
  if (L <= l && r <= R) {
    if (tr[t] < ans) ans = tr[t];
    return;
  }
  get_min(2 * t, l, (l + r) / 2);
  get_min(2 * t + 1, (l + r) / 2 + 1, r);
}
pair<pair<int, int>, int> q[1048576 / 2];
pair<int, int> P[1048576 / 2];
int lst[1048576 / 2], a[1048576 / 2], res[1048576 / 2];
int n, m, i, x, y, l, r, mid, upto, j;
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    scanf("%d", &a[i]), P[i].first = a[i], P[i].second = i;
  sort(P + 1, P + n + 1);
  a[P[1].second] = 1;
  for (i = 2; i <= n; i++)
    if (P[i].first == P[i - 1].first)
      a[P[i].second] = a[P[i - 1].second];
    else
      a[P[i].second] = a[P[i - 1].second] + 1;
  for (i = 1; i <= n; i++) lst[i] = 1048576;
  for (i = n; i >= 1; i--) {
    nxt[i] = lst[a[i]] - i;
    P[i].first = lst[a[i]];
    P[i].second = i;
    lst[a[i]] = i;
  }
  sort(P + 1, P + n + 1);
  upto = 1;
  build(1, 1, n);
  for (i = 1; i <= m; i++)
    scanf("%d%d", &q[i].first.second, &q[i].first.first), q[i].second = i;
  sort(q + 1, q + m + 1);
  for (j = 1; j <= m; j++) {
    i = q[j].second;
    x = q[j].first.second;
    y = q[j].first.first;
    while (upto <= n && P[upto].first <= y) {
      add(1, 1, n, P[upto].second);
      upto++;
    }
    L = x;
    R = y;
    ans = 1048576;
    get_min(1, 1, n);
    if (ans == 1048576) ans = -1;
    res[i] = ans;
  }
  for (j = 1; j <= m; j++) printf("%d\n", res[j]);
}
