#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& x) {
  char c;
  bool fu = 0;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') fu = 1, c = getchar();
  for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';
  if (fu) x *= -1;
}
template <class T>
inline void read(T& x, T& y) {
  read(x);
  read(y);
}
template <class T>
inline void read(T& x, T& y, T& z) {
  read(x, y);
  read(z);
}
const int N = 543210;
int n, m, a[N], l, r, b[N], c[N];
int t[4 * N];
map<int, int> pre;
vector<pair<int, int> > q[N];
int get(int l, int r, int cl, int cr, int v) {
  if (l == cl && cr == r) return t[v];
  int cm = (cl + cr) / 2;
  if (cm >= r) return get(l, r, cl, cm, v << 1);
  if (l > cm) return get(l, r, cm + 1, cr, (v << 1) + 1);
  return min(get(l, cm, cl, cm, v << 1),
             get(cm + 1, r, cm + 1, cr, (v << 1) + 1));
}
void upd(int p, int l, int cl, int cr, int v) {
  if (cl == cr)
    t[v] = min(t[v], l);
  else {
    int cm = (cl + cr) / 2;
    if (p <= cm)
      upd(p, l, cl, cm, v << 1);
    else
      upd(p, l, cm + 1, cr, (v << 1) + 1);
    t[v] = min(t[v << 1], t[(v << 1) + 1]);
  }
}
int main() {
  read(n, m);
  for (int _tmp = n, i = 1; i <= _tmp; ++i) read(a[i]);
  for (int _tmp = 4 * N - 1, i = 1; i <= _tmp; ++i) t[i] = 12345567;
  for (int _tmp = n, i = 1; i <= _tmp; ++i) {
    if (pre.count(a[i])) b[i] = pre[a[i]];
    pre[a[i]] = i;
  }
  for (int _tmp = m, i = 1; i <= _tmp; ++i) {
    int l, r;
    read(l, r);
    q[r].push_back(make_pair(l, i));
  }
  for (int _tmp = n, i = 1; i <= _tmp; ++i) {
    if (b[i] != 0) upd(b[i], i - b[i], 1, n, 1);
    for (; !q[i].empty(); q[i].pop_back())
      c[q[i].back().second] = get(q[i].back().first, i, 1, n, 1);
  }
  for (int _tmp = m, i = 1; i <= _tmp; ++i) {
    if (c[i] > n) c[i] = -1;
    printf("%d\n", c[i]);
  }
  return 0;
}
