#include <bits/stdc++.h>
using namespace std;
int n, m;
int l, r;
int v[500010];
int A[500010];
int T[500010 * 4];
map<int, int> M;
vector<pair<int, int> > E[500010];
void build(int l, int r, int node) {
  T[node] = 1e9;
  if (l == r) return;
  build(l, (l + r) / 2, node * 2);
  build((l + r) / 2 + 1, r, node * 2 + 1);
}
void upd(int pos, int x, int l, int r, int node) {
  if (l == r) {
    T[node] = x;
    return;
  }
  if (pos <= (l + r) / 2)
    upd(pos, x, l, (l + r) / 2, node * 2);
  else
    upd(pos, x, (l + r) / 2 + 1, r, node * 2 + 1);
  T[node] = min(T[node * 2], T[node * 2 + 1]);
}
int tap(int a, int b, int l, int r, int node) {
  if (l > b || r < a) return 1e9;
  if (l >= a && r <= b) return T[node];
  return min(tap(a, b, l, (l + r) / 2, node * 2),
             tap(a, b, (l + r) / 2 + 1, r, node * 2 + 1));
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
  build(1, n, 1);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &l, &r);
    E[r].push_back({l, i});
  }
  for (int i = 1; i <= n; i++) {
    if (M[v[i]]) upd(M[v[i]], i - M[v[i]], 1, n, 1);
    M[v[i]] = i;
    for (auto h : E[i]) {
      int ans = tap(h.first, i, 1, n, 1);
      if (ans == 1e9) ans = -1;
      A[h.second] = ans;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", A[i]);
}
