#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:640000000")
using namespace std;
pair<int, int> a[500011];
int b[500011];
vector<int> t[500011 << 2];
vector<int> fen[500011 << 2];
bool cmp(int lhs, int rhs) { return a[lhs].second < a[rhs].second; }
void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[v] = vector<int>(1, tl);
    fen[v] = vector<int>(1, a[tl].second - a[tl].first);
  } else {
    int tm = (tl + tr) >> 1;
    build(v + v, tl, tm);
    build(v + v + 1, tm + 1, tr);
    merge((t[v + v]).begin(), (t[v + v]).end(), (t[v + v + 1]).begin(),
          (t[v + v + 1]).end(), back_inserter(t[v]), cmp);
    fen[v].assign(t[v].size(), 1000000000);
    for (int _n((t[v].size()) - 1), i(0); i <= _n; ++i)
      for (int idx = i; idx < t[v].size(); idx = (idx | (idx + 1)))
        fen[v][idx] = min(fen[v][idx], a[t[v][i]].second - a[t[v][i]].first);
  }
}
int get(int v, int tl, int tr, int l, int r, int first) {
  if (l > r) return 1000000000;
  if (l == tl && tr == r) {
    int pos = upper_bound(t[v].begin(), t[v].end(), first, cmp) - t[v].begin();
    if (!pos) return 1000000000;
    --pos;
    int result = 1000000000;
    for (; pos >= 0; pos = (pos & (pos + 1)) - 1)
      result = min(result, fen[v][pos]);
    return result;
  }
  int tm = (tl + tr) >> 1;
  return min(get(v + v, tl, tm, l, min(r, tm), first),
             get(v + v + 1, tm + 1, tr, max(tm + 1, l), r, first));
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int _n((n)-1), i(0); i <= _n; ++i) scanf("%d", b + i);
  map<int, int> last;
  int cur = 0;
  for (int _n((n)-1), i(0); i <= _n; ++i) {
    if (last.find(b[i]) != last.end()) a[cur++] = make_pair(last[b[i]], i);
    last[b[i]] = i;
  }
  if (cur != 0) {
    sort(a, a + cur);
    build(1, 0, cur - 1);
  }
  while (m--) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (cur == 0) {
      printf("-1\n");
      continue;
    }
    --l, --r;
    int L = lower_bound(a, a + cur, make_pair(l, 0)) - a;
    a[cur].second = r;
    int R = get(1, 0, cur - 1, L, cur - 1, cur);
    printf("%d\n", (R == 1000000000) ? -1 : R);
  }
  return 0;
}
