#include <bits/stdc++.h>
using namespace std;
long long int n, m;
vector<long long int> a(500005), nex(500005, INT_MAX), pre(500005, INT_MAX);
map<long long int, long long int> ind;
vector<long long int> ans(500005);
long long int powmod(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
using S = long long int;
typedef struct data {
  S val;
} data;
struct data tree[4 * 500005];
struct data combine(struct data l, struct data r) {
  struct data res;
  res.val = min(l.val, r.val);
  return res;
}
struct data make_data(S val) {
  struct data res;
  res.val = val;
  if (val == 0) res.val = INT_MAX;
  return res;
}
void build(S vector, S tl, S tr) {
  if (tl == tr) {
    tree[vector] = make_data(abs(tl - pre[tl]));
  } else {
    S tm = (tl + tr) / 2;
    build(vector * 2, tl, tm);
    build(vector * 2 + 1, tm + 1, tr);
    tree[vector] = combine(tree[vector * 2], tree[vector * 2 + 1]);
  }
}
struct data query(S node, S tl, S tr, S l, S r) {
  if (l > r) return make_data(0);
  if (l == tl && r == tr) {
    return tree[node];
  }
  S tm = (tl + tr) / 2;
  struct data temp =
      combine(query(node * 2, tl, tm, l, min(r, tm)),
              query(node * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
  return temp;
}
void update(S vector, S tl, S tr, S pos, S new_val) {
  if (tl == tr) {
    tree[vector] = make_data(new_val);
  } else {
    S tm = (tl + tr) / 2;
    if (pos <= tm)
      update(vector * 2, tl, tm, pos, new_val);
    else
      update(vector * 2 + 1, tm + 1, tr, pos, new_val);
    tree[vector] = combine(tree[vector * 2], tree[vector * 2 + 1]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  for (long long int i = 1; i <= n; i++) {
    if (ind.find(a[i]) != ind.end()) pre[i] = ind[a[i]];
    ind[a[i]] = i;
  }
  ind.clear();
  for (long long int i = n; i >= 1; i--) {
    if (ind.find(a[i]) != ind.end()) nex[i] = ind[a[i]];
    ind[a[i]] = i;
  }
  build(1, 1, n);
  vector<pair<pair<long long int, long long int>, long long int>> q(m);
  for (long long int i = 0; i < m; i++) {
    cin >> q[i].first.first >> q[i].first.second;
    q[i].second = i;
  }
  sort(q.begin(), q.end());
  long long int curl = 0;
  for (long long int i = 0; i < m; i++) {
    long long int l = q[i].first.first, r = q[i].first.second;
    while (curl < l) {
      if (nex[curl] <= n) update(1, 1, n, nex[curl], INT_MAX);
      curl++;
    }
    ans[q[i].second] = query(1, 1, n, 1, r).val;
  }
  for (long long int i = 0; i < m; i++) {
    if (ans[i] > n) ans[i] = -1;
    cout << ans[i] << "\n";
  }
}
