#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
int b[20][1 << 20], a[1 << 20], s[1 << 20];
int get(int l, int r) {
  int len = r - l + 1;
  return min(b[a[len]][l], b[a[len]][r - s[len] + 1]);
}
void solve(int n, int m) {
  int i, j, k, t, q, w, h, l, r, l1, r1;
  map<int, int> mp;
  for (i = 0; i < 20; i++)
    for (j = 0; j < (1 << 20); j++) b[i][j] = 2e9;
  for (i = 0; i < n; i++) {
    scanf("%d", &t);
    if (mp.find(t) == mp.end()) {
      mp[t] = i;
    } else {
      b[0][i] = i - mp[t];
      mp[t] = i;
    }
  }
  for (t = 2, i = 1; i < 20; i++, t *= 2) {
    for (j = t; j < t + t; j++) {
      a[j] = i;
      s[j] = t;
    }
  }
  s[1] = 1;
  for (t = 1, i = 1; i < 20; i++, t *= 2) {
    for (j = 0; j + t < n; j++) b[i][j] = min(b[i - 1][j], b[i - 1][j + t]);
  }
  for (i = 0; i < m; i++) {
    scanf("%d%d", &l, &r);
    l--;
    r--;
    t = 1;
    while (t + l <= r && get(l + t, r) > t) {
      t = get(l + t, r);
    }
    if (t + l > r)
      printf("-1\n");
    else
      printf("%d\n", t);
  }
  printf("\n");
}
int main() {
#pragma comment(linker, "/STACK:268435456")
  int n, m;
  while (scanf("%d%d", &n, &m) != EOF) solve(n, m);
  return 0;
}
