#include <bits/stdc++.h>
using namespace std;
const int N = 100007;
const int MX = 1000007;
const int MOD = 1000000007;
const int INF = 2000000007;
const long long oo = 1000000000000000007;
const double eps = 1e-9;
const int xi[4] = {-1, 0, 1, 0};
const int yj[4] = {0, 1, 0, -1};
void IOI2017() {
  freopen(
      "segmentupdate"
      ".in",
      "r", stdin);
  freopen(
      "segmentupdate"
      ".out",
      "w", stdout);
}
const int sz = 5 * N;
int n, m;
int a[sz], nxt[sz], ans[sz], t[sz * 4];
vector<pair<int, int> > q[sz];
unordered_map<int, int> p;
inline void Build(int v = 1, int tl = 1, int tr = n) {
  if (tl == tr)
    t[v] = INF;
  else {
    int tm = tl + tr >> 1;
    Build(v + v, tl, tm);
    Build(v + v + 1, tm + 1, tr);
    t[v] = min(t[v + v], t[v + v + 1]);
  }
}
inline void Update(int pos, int val, int v = 1, int tl = 1, int tr = n) {
  if (tl == tr)
    t[v] = val;
  else {
    int tm = tl + tr >> 1;
    if (pos <= tm)
      Update(pos, val, v + v, tl, tm);
    else
      Update(pos, val, v + v + 1, tm + 1, tr);
    t[v] = min(t[v + v], t[v + v + 1]);
  }
}
inline int Get(int l, int r, int v = 1, int tl = 1, int tr = n) {
  if (l <= tl && tr <= r) return t[v];
  if (tl > r || tr < l) return INF;
  int tm = tl + tr >> 1;
  return min(Get(l, r, v + v, tl, tm), Get(l, r, v + v + 1, tm + 1, tr));
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  scanf("%d%d", &n, &m);
  Build();
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = n; i >= 1; i--) {
    nxt[i] = p[a[i]];
    p[a[i]] = i;
  }
  for (int i = 1, l, r; i <= m; i++)
    scanf("%d%d", &l, &r), q[l].push_back({r, i});
  for (int i = n; i >= 1; i--) {
    if (nxt[i]) Update(nxt[i], nxt[i] - i);
    for (auto j : q[i]) {
      int x = Get(i, j.first);
      if (x == INF)
        ans[j.second] = -1;
      else
        ans[j.second] = x;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
