#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 11;
const int oo = 0x3f3f3f3f;
int a[N];
struct Q {
  int id, l, r;
  bool operator<(const Q t) const { return r < t.r; }
} q[N];
int ans[N];
int minx[1 << 21];
void update(int cur) {
  int left = cur << 1, right = left | 1;
  minx[cur] = min(minx[left], minx[right]);
}
void build(int cur, int x, int y) {
  if (x == y) {
    minx[cur] = oo;
    return;
  }
  int left = cur << 1, right = left | 1, mid = (x + y) >> 1;
  build(left, x, mid);
  build(right, mid + 1, y);
  update(cur);
}
void change(int cur, int x, int y, int s, int t, int v) {
  if (s <= x && y <= t) {
    minx[cur] = v;
    return;
  }
  int left = cur << 1, right = left | 1, mid = (x + y) >> 1;
  if (s <= mid) change(left, x, mid, s, t, v);
  if (mid + 1 <= t) change(right, mid + 1, y, s, t, v);
  update(cur);
}
void query(int cur, int x, int y, int s, int t, int &ans) {
  if (s <= x && y <= t) {
    ans = min(ans, minx[cur]);
    return;
  }
  int left = cur << 1, right = left | 1, mid = (x + y) >> 1;
  if (s <= mid) query(left, x, mid, s, t, ans);
  if (mid + 1 <= t) query(right, mid + 1, y, s, t, ans);
}
int main() {
  int n, m;
  while (2 == scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &q[i].l, &q[i].r);
      q[i].id = i;
    }
    sort(q, q + m);
    int len = 1;
    while (len < n) len <<= 1;
    build(1, 1, len);
    map<int, int> last;
    int j = 1;
    for (int i = 0; i < m; i++) {
      while (j <= q[i].r) {
        int k = last[a[j]];
        if (k) {
          change(1, 1, len, k, k, j - k);
        }
        last[a[j]] = j;
        j++;
      }
      ans[q[i].id] = oo;
      query(1, 1, len, q[i].l, q[i].r, ans[q[i].id]);
    }
    for (int i = 0; i < m; i++) {
      printf("%d\n", ans[i] < oo ? ans[i] : -1);
    }
  }
  return 0;
}
