#include <bits/stdc++.h>
using namespace std;
map<int, int> M;
vector<pair<int, int> > V[500050];
int A[500050];
int ANS[500050] = {-1};
int BIT[500050];
int N, Q, L, R;
void update(int idx, int val) {
  for (int i = idx; i > 0; i -= i & -i) BIT[i] = min(BIT[i], val);
}
int query(int idx) {
  int res = 1000000009;
  for (int i = idx; i <= N; i += i & -i) res = min(res, BIT[i]);
  return res;
}
int main() {
  scanf("%d", &N);
  scanf("%d", &Q);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    BIT[i] = 1000000009;
  }
  for (int i = 1; i <= Q; i++) {
    scanf("%d", &L);
    scanf("%d", &R);
    V[R].push_back(make_pair(L, i));
  }
  for (int i = 1; i <= N; i++) {
    if (M.find(A[i]) != M.end()) update(M[A[i]], i - M[A[i]]);
    M[A[i]] = i;
    int sz = V[i].size();
    for (int j = 0; j < sz; j++) ANS[V[i][j].second] = query(V[i][j].first);
  }
  for (int i = 1; i <= Q; i++)
    printf("%d\n", ANS[i] == 1000000009 ? -1 : ANS[i]);
  ;
  return 0;
}
