#include <bits/stdc++.h>
using namespace std;
int ri() {
  int x;
  scanf("%d", &x);
  return x;
}
const int N = 500000;
int a[N], c[N], ans[N];
struct P {
  int l, r, i;
  bool operator<(const P& o) const { return r < o.r; }
} b[N];
int main() {
  int n = ri(), m = ri();
  for (int i = (0); i < (n); i++) a[i] = ri();
  for (int i = (0); i < (m); i++) {
    b[i].l = ri() - 1;
    b[i].r = ri();
    b[i].i = i;
  }
  sort(b, b + m);
  fill_n(ans, m, n);
  fill_n(c, n, n);
  map<int, int> l;
  int j = 0;
  for (int i = (0); i < (m); i++) {
    for (; j < b[i].r; j++) {
      if (l.count(a[j])) {
        int d = j - l[a[j]];
        for (int x = l[a[j]] + 1; x; x &= x - 1) c[x - 1] = min(c[x - 1], d);
      }
      l[a[j]] = j;
    }
    for (int x = b[i].l; x < n; x |= x + 1)
      ans[b[i].i] = min(ans[b[i].i], c[x]);
  }
  for (int i = (0); i < (m); i++) printf("%d\n", ans[i] == n ? -1 : ans[i]);
}
