#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
const int inf = 0x3f3f3f3f;
int a[MAXN], pre[MAXN], nt[MAXN];
int n, m;
map<int, int> mp;
int ans[MAXN];
struct QUERY {
  int l, r;
  int id;
  bool operator<(const QUERY &that) const { return l < that.l; }
} op[MAXN];
int tree[MAXN * 4];
void Build(int l, int r, int x) {
  if (l == r) {
    tree[x] = l - pre[l];
    return;
  }
  int mid = (l + r) / 2;
  Build(l, mid, x * 2);
  Build(mid + 1, r, x * 2 + 1);
  tree[x] = min(tree[x * 2], tree[x * 2 + 1]);
}
void Modify(int idx, int val, int l, int r, int x) {
  if (l == r) {
    tree[x] = val;
    return;
  }
  int mid = (l + r) / 2;
  if (idx <= mid)
    Modify(idx, val, l, mid, x * 2);
  else
    Modify(idx, val, mid + 1, r, x * 2 + 1);
  tree[x] = min(tree[x * 2], tree[x * 2 + 1]);
}
int Query(int L, int R, int l, int r, int x) {
  if (L == l && r == R) {
    return tree[x];
  }
  int mid = (l + r) / 2;
  if (R <= mid)
    return Query(L, R, l, mid, x * 2);
  else if (L > mid)
    return Query(L, R, mid + 1, r, x * 2 + 1);
  else
    return min(Query(L, mid, l, mid, x * 2),
               Query(mid + 1, R, mid + 1, r, x * 2 + 1));
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    auto it = mp.find(a[i]);
    if (it == mp.end())
      pre[i] = -inf;
    else
      pre[i] = it->second;
    mp[a[i]] = i;
  }
  mp.clear();
  for (int i = n; i >= 1; i--) {
    auto it = mp.find(a[i]);
    if (it == mp.end())
      nt[i] = inf;
    else
      nt[i] = it->second;
    mp[a[i]] = i;
  }
  Build(1, n, 1);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &op[i].l, &op[i].r);
    op[i].id = i;
  }
  sort(op, op + m);
  int now = 1;
  for (int i = 0; i < m; i++) {
    int L = op[i].l, R = op[i].r;
    while (now < L) {
      if (nt[now] <= n) Modify(nt[now], inf, 1, n, 1);
      now++;
    }
    int ret = Query(L, op[i].r, 1, n, 1);
    ans[op[i].id] = ret;
  }
  for (int i = 0; i < m; i++) {
    if (ans[i] >= inf)
      puts("-1");
    else
      cout << ans[i] << endl;
  }
}
