#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  scanf("%d%d", &n, &m);
  int d = 1;
  while (d * d < 2 * n) ++d;
  int l = n / d;
  if (n % d != 0) ++l;
  vector<int> val(l * d);
  for (int i = 0; i < val.size(); ++i) val[i] = 1000000003 + i;
  for (int i = 0; i < n; ++i) scanf("%d", &val[i]);
  vector<int> f(l * d, 1000000003);
  vector<int> h(l * d, -1000000003);
  map<int, int> mapchik;
  for (int i = 0; i < l * d; ++i) {
    int cur = val[i];
    if (mapchik.count(cur)) {
      int prev = mapchik[cur];
      f[prev] = i;
      h[i] = prev;
    }
    mapchik[cur] = i;
  }
  vector<vector<int> > answer(l, vector<int>(l, 1000000003));
  for (int i = 0; i < l; ++i)
    for (int j = i; j < l; ++j) {
      if (j > i) answer[i][j] = answer[i][j - 1];
      for (int k = d * j; k < d * j + d; ++k) {
        if (f[k] < d * j + d) answer[i][j] = min(f[k] - k, answer[i][j]);
        if (h[k] >= d * i) answer[i][j] = min(k - h[k], answer[i][j]);
      }
    }
  vector<int> toPrint;
  for (int r = 0; r < m; ++r) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    --y;
    int b1 = (x + d - 1) / d;
    int b2 = (y + 1) / d - 1;
    int toAdd;
    if (b2 < b1)
      toAdd = 1000000003 + 3;
    else
      toAdd = answer[b1][b2];
    for (int i = x; i < d * b1; ++i)
      if (f[i] <= y) toAdd = min(toAdd, f[i] - i);
    for (int i = d * (b2 + 1); i <= y; ++i)
      if (h[i] >= x) toAdd = min(toAdd, i - h[i]);
    toPrint.push_back(toAdd);
  }
  for (int i = 0; i < toPrint.size(); ++i)
    if (toPrint[i] >= 1000000003)
      printf("-1\n");
    else
      printf("%d\n", toPrint[i]);
}
