#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e6 + 7;
const int oo = 1e9 + 7;
int a[maxn], seg[maxn], n, m, ans[maxn];
pair<pair<int, int>, int> q[maxn];
vector<int> v[maxn];
map<int, int> last;
void update(int pos, int val, int tag, int s, int e) {
  if (s + 1 == e) {
    seg[tag] = val;
    return;
  }
  int mid = (s + e) / 2;
  if (pos < mid)
    update(pos, val, tag * 2, s, mid);
  else
    update(pos, val, tag * 2 + 1, mid, e);
  seg[tag] = min(seg[tag * 2], seg[tag * 2 + 1]);
}
int get(int l, int r, int tag, int s, int e) {
  if (s >= r || e <= l) return oo;
  if (s >= l && e <= r) return seg[tag];
  int mid = (s + e) / 2;
  return min(get(l, r, tag * 2 + 1, mid, e), get(l, r, tag * 2, s, mid));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int(i) = (1); (i) <= (n); ++(i)) cin >> a[i];
  for (__typeof((long long)maxn) i = (0) - ((0) > ((long long)maxn));
       i != ((long long)maxn) - ((0) > ((long long)maxn));
       i += 1 - 2 * ((0) > ((long long)maxn)))
    seg[i] = oo;
  for (int(i) = (1); (i) <= (m); ++(i)) {
    cin >> q[i].first.first >> q[i].first.second;
    v[q[i].first.second].push_back(i);
    q[i].second = i;
  }
  for (int(i) = (1); (i) <= (n); ++(i)) {
    if (last[a[i]]) {
      update(last[a[i]], i - last[a[i]], 1, 1, n + 1);
    }
    last[a[i]] = i;
    for (__typeof((v[i]).begin()) j = (v[i]).begin(); j != (v[i]).end(); ++j)
      ans[*j] = get(q[*j].first.first, q[*j].first.second + 1, 1, 1, n + 1);
  }
  for (int(i) = (1); (i) <= (m); ++(i))
    cout << ((ans[i] == oo) ? -1 : ans[i]) << '\n';
}
