#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 1, mg = 1 << 19;
int tr[2 * mg], n, m, ql[MAXN], qr[MAXN], qid[MAXN], ans[MAXN], ps_sz;
void update(int pos, int val) {
  tr[pos] = val;
  do {
    pos >>= 1;
    tr[pos] = min(tr[pos << 1], tr[pos << 1 | 1]);
  } while (pos);
}
int get(int l, int r) {
  if (l == r) return tr[l];
  if (l & 1) return min(tr[l], get(l + 1, r));
  if (!(r & 1)) return min(get(l, r - 1), tr[r]);
  return get(l >> 1, r >> 1);
}
unordered_map<int, int> mp;
pair<int, int> ps[MAXN];
inline bool comp(int l, int r) { return qr[l] < qr[r]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1, a; i <= n; i++) {
    cin >> a;
    if (mp.find(a) == mp.end()) {
      mp[a] = i;
      continue;
    }
    ps[ps_sz++] = {i, mp[a]};
    mp[a] = i;
  }
  sort(ps, ps + ps_sz);
  ps[ps_sz] = {INT_MAX, INT_MAX};
  for (int i = 1; i <= m; i++) {
    cin >> ql[i] >> qr[i];
    qid[i] = i;
  }
  sort(qid + 1, qid + m + 1, comp);
  fill(tr, tr + 2 * mg, INT_MAX);
  for (int i = 1, res, it = 0; i <= m; i++) {
    while (ps[it].first <= qr[qid[i]])
      update(ps[it].second + mg, ps[it].first - ps[it].second), it++;
    if (INT_MAX == (res = get(ql[qid[i]] + mg, qr[qid[i]] + mg))) res = -1;
    ans[qid[i]] = res;
  }
  for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
  return 0;
}
