#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500100, INF = (1 << 29);
unordered_map<int, int> lst;
int a[MAXN], ans[MAXN], n, m;
int r[MAXN];
vector<pair<int, int> > q[MAXN];
int tree[MAXN * 5];
int getMin(int v, int l, int r, int st, int fin) {
  if (l == st && r == fin) {
    return tree[v];
  }
  int med = (l + r) / 2;
  if (fin <= med) {
    return getMin(2 * v + 1, l, med, st, fin);
  }
  if (st > med) {
    return getMin(2 * v + 2, med + 1, r, st, fin);
  }
  return min(getMin(2 * v + 1, l, med, st, med),
             getMin(2 * v + 2, med + 1, r, med + 1, fin));
}
void modify(int v, int l, int r, int pos, int val) {
  if (l == r) {
    tree[v] = val;
    return;
  }
  int med = (l + r) / 2;
  if (pos <= med) {
    modify(2 * v + 1, l, med, pos, val);
  } else {
    modify(2 * v + 2, med + 1, r, pos, val);
  }
  tree[v] = min(tree[2 * v + 1], tree[2 * v + 2]);
}
int main() {
  for (int i = 0; i < 5 * MAXN; i++) {
    tree[i] = INF;
  }
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < m; i++) {
    int aa, bb;
    scanf("%d%d", &aa, &bb);
    aa--;
    bb--;
    q[bb].push_back(make_pair(aa, i));
  }
  for (int i = 0; i < n; i++) {
    int prev = -1;
    if (lst.find(a[i]) != lst.end()) {
      prev = lst[a[i]];
    }
    lst[a[i]] = i;
    if (prev != -1) {
      int dist = i - prev;
      modify(0, 0, n - 1, prev, dist);
    }
    for (int j = 0; j < q[i].size(); j++) {
      ans[q[i][j].second] = getMin(0, 0, n - 1, q[i][j].first, i);
    }
  }
  for (int i = 0; i < m; i++) {
    if (ans[i] == INF) {
      ans[i] = -1;
    }
    printf("%d\n", ans[i]);
  }
  return 0;
}
