#include <bits/stdc++.h>
using namespace std;
namespace my_std {
bool ccc(long long a, long long b) { return a > b; }
long long my_pow(long long a, long long b, long long mod) {
  long long res = 1;
  if (!b) return 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
long long qpow(long long a, long long b) {
  long long res = 1;
  if (!b) return 1;
  while (b) {
    if (b & 1) res *= a;
    a *= a;
    b >>= 1;
  }
  return res;
}
inline long long read() {
  long long sum = 0, f = 1;
  char ch = 0;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    sum = sum * 10 + (ch ^ 48);
    ch = getchar();
  }
  return sum * f;
}
inline void write(long long x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  putchar('\n');
}
inline void writesp(long long x) {
  write(x);
  putchar(' ');
}
}  // namespace my_std
using namespace my_std;
map<long long, long long> lst;
long long n, m, a[500050], l[500050], r[500050], cnt = 0, ql, qr;
long long lg[500050], f[500050][33];
int main() {
  n = read();
  m = read();
  for (register long long i = (1); i <= (n); i++) {
    a[i] = read();
    if (lst[a[i]] > l[cnt]) {
      l[++cnt] = lst[a[i]];
      r[cnt] = i;
    }
    lst[a[i]] = i;
  }
  for (register long long i = (1); i <= (cnt); i++) f[i][0] = r[i] - l[i];
  for (long long j = 1; (1 << j) <= cnt; j++)
    for (register long long i = (1); i <= (cnt - (1 << j) + 1); i++)
      f[i][j] = min(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
  lg[1] = 0;
  lg[2] = 1;
  for (register long long i = (3); i <= (n); i++) lg[i] = lg[i >> 1] + 1;
  while (m--) {
    ql = read();
    qr = read();
    long long ansl = lower_bound(l + 1, l + cnt + 1, ql) - l,
              ansr = upper_bound(r + 1, r + cnt + 1, qr) - r - 1;
    if (ansl > ansr)
      writeln(-1);
    else
      writeln(
          min(f[ansl][lg[ansr - ansl + 1]],
              f[ansr - (1 << lg[ansr - ansl + 1]) + 1][lg[ansr - ansl + 1]]));
  }
}
