#include <bits/stdc++.h>
using namespace std;
struct T {
  int r;
  int postponed_min;
  int index;
};
bool operator<(T a, T b) { return a.r < b.r; }
const int inf = 1e9;
const int N = 5e5 + 100;
T w[N];
T t[N * 4];
int a[N];
int n, m;
pair<int, int> queries[N];
vector<int> ls[N];
vector<int> rs[N];
vector<int> e[N];
int nxt[N];
int where_index[N];
int ans[N];
void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[v] = w[tl];
    return;
  }
  int m = (tl + tr) / 2;
  build(v * 2, tl, m);
  build(v * 2 + 1, m + 1, tr);
}
void push(int v) {
  if (t[v].postponed_min != inf) {
    t[v * 2].postponed_min = min(t[v].postponed_min, t[v * 2].postponed_min);
    t[v * 2 + 1].postponed_min =
        min(t[v].postponed_min, t[v * 2 + 1].postponed_min);
    t[v].postponed_min = inf;
  }
}
void update(int v, int tl, int tr, int l, int r, int val) {
  if (l > r) return;
  if (tl == l && r == tr) {
    t[v].postponed_min = min(val, t[v].postponed_min);
    return;
  }
  push(v);
  int m = (tl + tr) / 2;
  update(v * 2, tl, m, l, min(r, m), val);
  update(v * 2 + 1, m + 1, tr, max(l, m + 1), r, val);
}
int get(int v, int tl, int tr, int pos) {
  if (tl == tr) {
    return t[v].postponed_min;
  }
  push(v);
  int m = (tl + tr) / 2;
  if (pos <= m)
    return get(v * 2, tl, m, pos);
  else
    return get(v * 2 + 1, m + 1, tr, pos);
}
void make_inf(int v, int tl, int tr, int pos) {
  if (tl == tr) {
    t[v].postponed_min = inf;
    return;
  }
  push(v);
  int m = (tl + tr) / 2;
  if (pos <= m)
    make_inf(v * 2, tl, m, pos);
  else
    make_inf(v * 2 + 1, m + 1, tr, pos);
}
map<int, int> compresser;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    int res = 0;
    if (compresser.find(a[i]) == compresser.end())
      res = compresser[a[i]] = compresser.size();
    else
      res = compresser[a[i]];
    a[i] = res;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (e[a[i]].empty())
      nxt[i] = inf;
    else
      nxt[i] = e[a[i]][e[a[i]].size() - 1];
    e[a[i]].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--, r--;
    queries[i] = make_pair(l, r);
    ls[l].push_back(i);
    rs[r].push_back(i);
    w[i].postponed_min = inf;
    w[i].index = i;
    w[i].r = r;
  }
  sort(w, w + m);
  reverse(w, w + m);
  for (int i = 0; i < m; i++) {
    where_index[w[i].index] = i;
  }
  build(1, 0, m - 1);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < ls[i].size(); j++) {
      make_inf(1, 0, m - 1, where_index[ls[i][j]]);
    }
    for (int j = 0; j < rs[i].size(); j++) {
      int ind = where_index[rs[i][j]];
      int res = get(1, 0, m - 1, ind);
      ans[rs[i][j]] = res;
    }
    if (nxt[i] == inf) continue;
    int min_r = nxt[i];
    int l = -1, r = m;
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (w[mid].r < min_r)
        r = mid;
      else
        l = mid;
    }
    update(1, 0, m - 1, 0, l, nxt[i] - i);
  }
  for (int i = 0; i < m; i++) {
    if (ans[i] == inf)
      printf("-1");
    else
      printf("%d", ans[i]);
    printf("\n");
  }
  return 0;
}
