#include <bits/stdc++.h>
using namespace std;
const long long A = 100000000000000LL, N = 528228;
map<int, int> g, h;
pair<pair<long long, long long>, long long> p[N];
long long ot[N], w, x = 1, po[N], r[N], i, j, n, q[N * 4], t[N * 4], m, o, a[N],
                    b[N], _b[N];
void modi(long long v, long long l, long long r, long long g, long long h) {
  if (g == A) return;
  if (l == r) {
    t[v] = h;
    q[v] = g;
    return;
  }
  long long mid = (l + r) / 2;
  if (mid >= g)
    modi(v * 2, l, mid, g, h);
  else
    modi(v * 2 + 1, mid + 1, r, g, h);
  if (t[v * 2] > t[v * 2 + 1])
    t[v] = t[v * 2 + 1], q[v] = q[v * 2 + 1];
  else
    t[v] = t[v * 2], q[v] = q[v * 2];
}
void get(long long v, long long l, long long r, long long _l, long long _r) {
  if (_l > _r || l > r) return;
  if (l == _l && r == _r) {
    if (t[v] < o) o = t[v], w = q[v];
    return;
  }
  long long mid = (l + r) / 2;
  get(v * 2, l, mid, _l, min(_r, mid));
  get(v * 2 + 1, mid + 1, r, max(_l, mid + 1), _r);
}
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) {
    if (g[a[i]] == 0)
      r[i] = A;
    else
      r[i] = i - g[a[i]];
    g[a[i]] = i;
    modi(1, 1, n, i, r[i]);
  }
  for (i = n; i >= 1; i--) {
    if (h[a[i]] == 0)
      po[i] = A;
    else
      po[i] = h[a[i]];
    h[a[i]] = i;
  }
  for (i = 0; i < m; i++)
    scanf("%d %d", &p[i].first.first, &p[i].first.second), p[i].second = i;
  sort(p, p + m);
  for (i = 0; i < m; i++) {
    for (j = x; j < p[i].first.first; j++) modi(1, 1, n, po[j], A);
    o = A;
    get(1, 1, n, 1, p[i].first.second);
    if (o == A)
      ot[p[i].second] = -1;
    else
      ot[p[i].second] = o;
    x = p[i].first.first;
  }
  for (i = 0; i < m; i++) printf("%d\n", ot[i]);
}
