#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
const int N = 5e5 + 100;
vector<int> Q[N];
vector<int> add[N];
pair<int, int> a[N];
int bit[N];
int n, q;
void Updata(int x, int y) {
  while (x <= n) {
    bit[x] = min(bit[x], y);
    x += x & (-x);
  }
}
int Query(int x) {
  int ret = N + 1;
  while (x > 0) {
    ret = min(ret, bit[x]);
    x -= x & (-x);
  }
  return ret;
}
int l[N], r[N];
int ans[N];
int Ac() {
  fill(bit, bit + N, N + 1);
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i < n; ++i) {
    if (a[i].first == a[i + 1].first) {
      add[a[i].second].push_back(a[i + 1].second);
    }
  }
  for (int i = 1; i <= q; ++i) {
    scanf("%d%d", &l[i], &r[i]);
    Q[l[i]].push_back(i);
  }
  for (int i = n; i >= 1; --i) {
    for (auto& v : add[i]) {
      Updata(v, v - i);
    }
    for (auto& v : Q[i]) {
      ans[v] = Query(r[v]);
      if (ans[v] == N + 1) ans[v] = -1;
    }
  }
  for (int i = 1; i <= q; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
int main() {
  Ac();
  return 0;
}
