#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long spf[101];
long long fac[101];
void sieve() {
  spf[1] = 1;
  for (long long i = 2; i < 101; i++) spf[i] = i;
  for (long long i = 4; i < 101; i += 2) spf[i] = 2;
  for (long long i = 3; i * i < 101; i++) {
    if (spf[i] == i) {
      for (long long j = i * i; j < 101; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
map<long long, long long> getfactor(long long a) {
  map<long long, long long> m;
  while (a > 1) {
    m[spf[a]]++;
    a /= spf[a];
  }
  return m;
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long inverse(long long a, long long p) { return power(a, p - 2, p); }
long long ncr(long long n, long long r, long long p) {
  if (r == 0) return 1;
  return (fac[n] * inverse(fac[r], p) % p * inverse(fac[n - r], p) % p) % p;
}
long long seg[2000009];
void update(long long v, long long l, long long r, long long pos,
            long long val) {
  if (l == r) {
    seg[v] = min(val, seg[v]);
    return;
  }
  long long mid = (l + r) / 2;
  if (pos <= mid)
    update(v * 2, l, mid, pos, val);
  else
    update(v * 2 + 1, mid + 1, r, pos, val);
  seg[v] = min(seg[v * 2], seg[v * 2 + 1]);
}
long long query(long long v, long long l, long long r, long long posl,
                long long posr) {
  if (l >= posl && r <= posr)
    return seg[v];
  else if (l > posr || r < posl)
    return 1e18;
  long long mid = (l + r) / 2;
  return min(query(v * 2, l, mid, posl, posr),
             query(v * 2 + 1, mid + 1, r, posl, posr));
}
void solve() {
  for (long long i = 1; i <= 2000000; i++) seg[i] = 1e18;
  long long n, ma;
  cin >> n >> ma;
  map<long long, long long> m;
  long long a[n + 1];
  for (long long i = 1; i <= n; i++) cin >> a[i];
  vector<pair<long long, long long> > v[n + 1];
  long long ans[ma + 1];
  for (long long i = 1; i <= ma; i++) {
    long long l, r;
    cin >> l >> r;
    v[r].push_back(make_pair(l, i));
  }
  for (long long i = 1; i <= n; i++) {
    if (m.find(a[i]) != m.end()) {
      update(1, 1, n, m[a[i]], i - m[a[i]]);
    }
    m[a[i]] = i;
    for (auto it : v[i]) {
      ans[it.second] = query(1, 1, n, it.first, i);
    }
  }
  for (long long i = 1; i <= ma; i++) {
    if (ans[i] != 1e18)
      cout << ans[i] << '\n';
    else
      cout << -1 << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
