#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int sz = 524288;
int b[sz + sz + 6], nestet, n, m, y, l, r, x, numbeer;
int ans[sz + sz + 3], t[sz + sz + 6], a[sz + sz + 7];
map<int, int> neste, sledushiy;
vector<pair<int, pair<int, int> > > v;
int build_tree(int v, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) return t[v];
  if (rr < l || r < ll) return inf;
  int c = (r + l) >> 1;
  return min(build_tree(v + v, l, c, ll, rr),
             build_tree(v + v + 1, c + 1, r, ll, rr));
}
void update(int v, int val) {
  t[v] = val;
  v >>= 1;
  for (; v;) {
    t[v] = min(t[v + v], t[v + v + 1]);
    v >>= 1;
  }
}
void tree(int r) {
  for (int i = nestet; i <= r; ++i) {
    if (sledushiy[i] == 0) continue;
    int w = sledushiy[i];
    update(sz + w - 1, inf);
  }
  nestet = r;
}
void BuilD(int v, int l, int r) {
  if (l == r) {
    t[v] = a[l];
    return;
  }
  int c = (r + l) >> 1;
  BuilD(v + v, l, c);
  BuilD(v + v + 1, c + 1, r);
  t[v] = min(t[v + v], t[v + v + 1]);
}
int q;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    b[i] = x;
    if (!neste[x]) {
      neste[x] = i;
      a[i] = inf;
    } else {
      sledushiy[neste[x]] = i;
      a[i] = (i - neste[x]);
      neste[x] = i;
    }
  }
  for (int i = n + 1; i <= sz; ++i) a[i] = inf;
  BuilD(1, 1, sz);
  for (int i = 1; i <= m; ++i) {
    cin >> x >> y;
    v.push_back(make_pair(x, make_pair(y, i)));
  }
  sort(v.begin(), v.end());
  nestet = 1;
  for (int i = 0; i < v.size(); ++i) {
    l = v[i].first;
    tree(l - 1);
    r = v[i].second.first;
    numbeer = v[i].second.second;
    q = build_tree(1, 1, sz, l, r);
    if (q == inf) q = -1;
    ans[numbeer] = q;
  }
  for (int i = 1; i <= m; + i++) printf("%d\n", ans[i]);
  return 0;
}
