#include <bits/stdc++.h>
using namespace std;
struct Pair {
  int x, position;
} valiue[543211], b[543211];
int n, k, len, N, Partition, L, R;
int QWER[543211], REWQ[543211], otvet[543211], kol, i;
int Lowofbound[543211], Behind[543211], sled[543211], l, r, mn;
vector<pair<pair<int, int>, int> > a[800];
bool cmd(Pair q, Pair w) {
  if (q.position < w.position)
    return true;
  else
    return false;
}
bool cmp(Pair q, Pair w) {
  if (q.x < w.x)
    return true;
  else
    return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (i = 1; i <= n; ++i) {
    cin >> valiue[i].x;
    b[i].position = i;
    b[i].x = valiue[i].x;
  }
  sort(b + 1, b + n + 1, cmp);
  len = 0;
  for (i = 1; i <= n; ++i) {
    if (i == 1 || b[i].x != b[i - 1].x) {
      ++len;
    }
    valiue[i].x = len;
    valiue[i].position = b[i].position;
  }
  sort(valiue + 1, valiue + n + 1, cmd);
  N = int(sqrt(n));
  for (i = 1; i <= k; ++i) {
    cin >> l >> r;
    Partition = (l - 1) / N + 1;
    a[Partition].push_back(make_pair(make_pair(r, l), i));
  }
  for (i = 1; i <= n; ++i) {
    if (!QWER[valiue[i].x])
      QWER[valiue[i].x] = i;
    else
      Behind[i] = QWER[valiue[i].x], QWER[valiue[i].x] = i;
  }
  for (i = n; i >= 1; --i) {
    if (!REWQ[valiue[i].x])
      REWQ[valiue[i].x] = i;
    else
      sled[i] = REWQ[valiue[i].x], REWQ[valiue[i].x] = i;
  }
  for (i = 1; i <= n; ++i) Lowofbound[(i - 1) / N + 1] = i;
  for (i = 1; i <= 720; ++i)
    if (a[i].size() > 0) {
      sort(a[i].begin(), a[i].end());
      mn = 2000000000;
      R = Lowofbound[i];
      L = R + 1;
      for (int j = 0; j < a[i].size(); ++j) {
        l = a[i][j].first.second;
        r = a[i][j].first.first;
        if (L <= r) {
          while (R < r) {
            R++;
            if (Behind[R] > Lowofbound[i]) mn = min(mn, R - Behind[R]);
          }
          kol = mn;
          for (int c = Lowofbound[i]; c >= l; --c)
            if (sled[c] > 0 && sled[c] <= R) kol = min(kol, sled[c] - c);
        } else {
          kol = mn;
          for (int c = l; c <= r; ++c)
            if (sled[c] > 0 && sled[c] <= r) kol = min(kol, sled[c] - c);
        }
        if (kol != 2000000000)
          otvet[a[i][j].second] = kol;
        else
          otvet[a[i][j].second] = -1;
      }
    }
  for (i = 1; i <= k; ++i) cout << otvet[i] << endl;
  return 0;
}
