#include <bits/stdc++.h>
using namespace std;
int N, Q, l, r;
int A[500100], D[500100], V[500100];
map<int, int> M;
int b[500100 * 4], e[500100 * 4], tree[500100 * 4];
void init(int n, int beg, int end) {
  b[n] = beg;
  e[n] = end;
  if (beg == end) {
    tree[n] = V[beg];
    return;
  }
  int m = beg + (end - beg) / 2;
  init(2 * n, beg, m);
  init(2 * n + 1, m + 1, end);
  tree[n] = min(tree[2 * n], tree[2 * n + 1]);
}
int query(int n) {
  if (b[n] > r || e[n] < l) return N + 1;
  if (b[n] >= l && e[n] <= r) return tree[n];
  return min(query(2 * n), query(2 * n + 1));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> Q;
  for (long long I = 1; I <= N; I++) {
    cin >> A[I];
    int l = M[A[I]];
    D[I] = max(D[I - 1], l);
    V[l] = I - l;
    M[A[I]] = I;
  }
  for (__typeof((M).begin()) it = (M).begin(); it != (M).end(); it++)
    V[it->second] = N + 1;
  init(1, 1, N);
  for (long long q = 1; q <= Q; q++) {
    cin >> l >> r;
    r = D[r];
    if (l > r)
      cout << -1 << "\n";
    else {
      int ret = query(1);
      if (ret == N + 1) ret = -1;
      cout << ret << "\n";
    }
  }
}
