#include <bits/stdc++.h>
using namespace std;
const int maxn = 500050;
int n, m, a[maxn], l[maxn], r[maxn], ans[maxn];
map<int, int> ap;
int ord[maxn];
int tr[maxn];
bool cmp(const int &xx, const int &yy) { return r[xx] < r[yy]; }
inline void modify(int x, int k) {
  while (x) tr[x] = min(tr[x], k), x -= x & -x;
}
inline int query(int x) {
  int s = maxn;
  while (x <= n) s = min(s, tr[x]), x += x & -x;
  return s == maxn ? -1 : s;
}
int main() {
  int i, j, t;
  memset(tr, 0x3f, sizeof(tr));
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 0; i < m; i++) ord[i] = i, scanf("%d%d", &l[i], &r[i]);
  sort(ord, ord + m, cmp);
  for (i = 0, j = 1; i < m; i++) {
    t = ord[i];
    while (j <= r[t]) {
      if (ap.count(a[j])) modify(ap[a[j]], j - ap[a[j]]);
      ap[a[j]] = j;
      j++;
    }
    ans[t] = query(l[t]);
  }
  for (i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}
