#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e5 + 11;
const int INF = (int)1e9;
struct tree {
  vector<int> a;
  tree() { a.assign(N * 4, INF); }
  void upd(int id, int l, int r, int k, int v) {
    if (l == r) {
      a[id] = v;
      return;
    }
    int mid = (l + r) / 2;
    if (k <= mid)
      upd(id * 2, l, mid, k, v);
    else
      upd(id * 2 + 1, mid + 1, r, k, v);
    a[id] = min(a[id * 2], a[id * 2 + 1]);
  }
  int getMin(int id, int l, int r, int u, int v) {
    if (l > v || r < u) return INF;
    if (u <= l && r <= v) return a[id];
    int mid = (l + r) / 2;
    return min(getMin(id * 2, l, mid, u, v),
               getMin(id * 2 + 1, mid + 1, r, u, v));
  }
} it;
struct query {
  int r, id;
};
vector<query> f[N];
vector<int> tmp;
int n, m, a[N], res[N];
int Prev[N], nxt[N];
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    tmp.push_back(a[i]);
  }
  for (int i = 1; i <= m; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    f[l].push_back({r, i});
  }
  sort(tmp.begin(), tmp.end());
  for (int i = 1; i <= n; ++i) {
    int k = lower_bound(tmp.begin(), tmp.end(), a[i]) - tmp.begin() + 1;
    nxt[Prev[k]] = i;
    Prev[k] = i;
  }
  for (int i = n; i >= 1; --i) {
    if (nxt[i] != 0) it.upd(1, 1, n, nxt[i], nxt[i] - i);
    for (int j = 0; j < (int)f[i].size(); ++j) {
      int r = f[i][j].r, id = f[i][j].id;
      res[id] = it.getMin(1, 1, n, i, r);
      if (res[id] == INF) res[id] = -1;
    }
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", res[i]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
