#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-16;
const int N = 500009;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int a[N];
int b[N];
map<int, int> last;
vector<pair<int, int> > t[4 * N];
void init(int v) {
  for (int i = ((int)t[v].size()) - 2; i >= 0; i--) {
    t[v][i].second = min(t[v][i].second, t[v][i + 1].second);
  }
}
void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[v] = vector<pair<int, int> >(
        1, make_pair(b[tl], b[tl] == 0 ? inf : tl - b[tl]));
    t[v].push_back(make_pair(inf, inf));
  } 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]));
  }
  init(v);
}
int get(int v, int tl, int tr, int l, int r, int L) {
  if (l > r) {
    return inf;
  }
  if (l == tl && r == tr) {
    return lower_bound(t[v].begin(), t[v].end(), make_pair(L, 0))->second;
  } else {
    int tm = (tl + tr) >> 1;
    return min(get(v + v, tl, tm, l, min(tm, r), L),
               get(v + v + 1, tm + 1, tr, max(l, tm + 1), r, L));
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    b[i] = last[a[i]];
    last[a[i]] = i;
  }
  build(1, 1, n);
  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    int res = get(1, 1, n, l, r, l);
    if (res == inf) {
      res = -1;
    }
    printf("%d\n", res);
  }
  return 0;
}
