#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;
const long long inf = (long long)1e16;
const long long upper = (long long)5e5 + 50;
const long long M = (long long)1e9 + 7;
const long long mod = (long long)998244353;
const double eps = 1e-8;
long long n, m;
long long tree[4 * upper];
void update(long long node, long long l, long long r, long long idx,
            long long val) {
  if (r < idx or l > idx) return;
  if (l == r) {
    tree[node] = val;
    return;
  }
  long long mid = (l + r) >> 1;
  update(2 * node + 1, l, mid, idx, val);
  update(2 * node + 2, mid + 1, r, idx, val);
  tree[node] = min(tree[2 * node + 1], tree[2 * node + 2]);
}
long long qry;
void query(long long node, long long l, long long r, long long lq,
           long long rq) {
  if (lq > r or rq < l) return;
  if (l >= lq and r <= rq) {
    qry = min(qry, tree[node]);
    return;
  }
  long long mid = (l + r) >> 1;
  query(2 * node + 1, l, mid, lq, rq);
  query(2 * node + 2, mid + 1, r, lq, rq);
}
vector<pair<long long, long long>> queries[upper];
long long frst[upper];
long long ans[upper];
long long arr[upper];
long long arr2[upper];
map<long long, long long> comp;
signed main() {
  long long begtime = clock();
  ;
  cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false);
  for (long long i = 0; i < upper; i += 1) frst[i] = inf;
  for (long long i = 0; i < 4 * upper; i += 1) tree[i] = inf;
  cin >> n >> m;
  for (long long i = 1; i <= n; i += 1) {
    cin >> arr[i];
    arr2[i] = arr[i];
  }
  sort(arr2 + 1, arr2 + n + 1);
  long long cur = 0, cur_num = -inf;
  for (long long i = 1; i <= n; i += 1) {
    if (arr2[i] > cur_num) {
      cur += 1;
      comp[arr2[i]] = cur;
      cur_num = arr2[i];
    }
  }
  for (long long i = 1; i <= n; i += 1) {
    arr[i] = comp[arr[i]];
  }
  for (long long i = 1; i <= m; i += 1) {
    long long l, r;
    cin >> l >> r;
    queries[l].push_back(make_pair(r, i));
  }
  for (long long i = n; i >= 1; i -= 1) {
    long long already = frst[arr[i]];
    if (already != inf) {
      update(1, 1, n, already, already - i);
    }
    frst[arr[i]] = i;
    for (auto j : queries[i]) {
      qry = inf;
      query(1, 1, n, i, j.first);
      if (qry != inf)
        ans[j.second] = qry;
      else
        ans[j.second] = -1;
    }
  }
  for (long long i = 1; i <= m; i += 1) {
    cout << ans[i] << '\n';
  }
  long long endtime = clock();
  cerr << '\n'
       << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC
       << " ms";
  return 0;
}
