#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
vector<int> Array;
class st {
 private:
  vector<int> t;
  int len;

 public:
  st(vector<int> &a) {
    len = a.size();
    t.resize(4 * len, inf);
    for (int i = len + 1; i <= 2 * len; ++i) t[i] = a[i - len - 1];
    for (int i = len; i >= 0; --i) t[i] = min(t[2 * i], t[2 * i + 1]);
  }
  int rmq(int l, int r) {
    l++;
    r++;
    int res = inf;
    if (l > r) return res;
    for (l += len, r += len; l <= r; l = (l + 1) / 2, r = (r - 1) / 2) {
      if (l % 2 == 1) res = min(res, t[l]);
      if (r % 2 == 0) res = min(res, t[r]);
    }
    return res;
  }
};
bool cmp(int first, int second) { return Array[first] < Array[second]; }
inline void MakeShortArray(vector<int> &indexArray, vector<int> &shortArray) {
  int count = 0;
  shortArray[indexArray[0]] = count;
  for (int i = 1; i < indexArray.size(); i++)
    shortArray[indexArray[i]] =
        (Array[indexArray[i - 1]] == Array[indexArray[i]]) ? count : ++count;
}
inline void FillNearestLeftNeighborArray(int n,
                                         vector<int> &leftNearestNeighbor,
                                         vector<int> &shortArray) {
  vector<int> leftNearestNeighborPosition(n, -1);
  for (int i = 0; i < shortArray.size(); i++) {
    leftNearestNeighbor[i] =
        leftNearestNeighborPosition[shortArray[i]] == -1
            ? inf
            : i - leftNearestNeighborPosition[shortArray[i]];
    leftNearestNeighborPosition[shortArray[i]] = i;
  }
}
inline void FillArrayOfNewLeftPosition(vector<int> &NearestNeighbor,
                                       vector<int> &newLeftPosition) {
  int _min = inf;
  for (int i = NearestNeighbor.size() - 1; i >= 0; i--) {
    newLeftPosition[i] = min(_min, newLeftPosition[i]);
    if (NearestNeighbor[i] != inf) newLeftPosition[i - NearestNeighbor[i]] = i;
    _min = min(_min, newLeftPosition[i]);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  Array.resize(n);
  vector<int> indexArray(n);
  int a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    Array[i] = a;
    indexArray[i] = i;
  }
  vector<int> shortArray(n);
  sort(indexArray.begin(), indexArray.end(), cmp);
  MakeShortArray(indexArray, shortArray);
  vector<int> leftNearestNeighbor(n);
  vector<int> newLeftPosition(n, inf);
  FillNearestLeftNeighborArray(n, leftNearestNeighbor, shortArray);
  FillArrayOfNewLeftPosition(leftNearestNeighbor, newLeftPosition);
  st *minimizator = new st(leftNearestNeighbor);
  int l, r, ans;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &l, &r);
    l--;
    r--;
    l = newLeftPosition[l];
    ans = minimizator->rmq(l, r);
    printf("%d\n", ans == inf ? -1 : ans);
  }
  return 0;
}
