#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infl = 0x3f3f3f3f3f3f3f3fLL;
template <class T>
void rd(T &a) {
  char ch = getchar();
  bool ng = 0;
  a = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') ng = 1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    a = (a << 1) + (a << 3) + (ch ^ '0');
  if (ng) a = ~a + 1;
}
template <class T>
void wrt(T a) {
  if (a < 0) {
    putchar('-');
    wrt(~a + 1);
  } else {
    if (a > 9) wrt(a / 10);
    putchar(a % 10 ^ '0');
  }
}
const int N = 5e5 + 5;
int n, q, nxt[N], a[N], ans[N];
map<int, int> pos;
vector<pair<int, int> > Q[N];
int fen[N];
void upd(int p, int x) {
  for (; p <= n; p += p & (-p)) fen[p] = min(fen[p], x);
}
int get(int p) {
  int res = inf;
  for (; p; p -= p & (-p)) res = min(res, fen[p]);
  return res;
}
int main() {
  rd(n), rd(q);
  for (int i = 1; i <= n; ++i) rd(a[i]);
  for (int i = n; i; --i) {
    if (pos.count(a[i]))
      nxt[i] = pos[a[i]];
    else
      nxt[i] = -1;
    pos[a[i]] = i;
  }
  for (int i = 1; i <= n; ++i) fen[i] = inf;
  for (int i = 1; i <= q; ++i) {
    int l, r;
    rd(l), rd(r);
    Q[l].push_back(pair<int, int>(r, i));
  }
  for (int i = n; i; --i) {
    if (~nxt[i]) upd(nxt[i], nxt[i] - i);
    for (int j = 0; j < (int)((Q[i]).size()); ++j) {
      int r = Q[i][j].first, id = Q[i][j].second;
      ans[id] = get(r);
    }
  }
  for (int i = 1; i <= q; ++i) {
    if (ans[i] >= inf)
      puts("-1");
    else
      wrt(ans[i]), puts("");
  }
  return 0;
}
