#include <bits/stdc++.h>
using namespace std;
class C_ {};
template <typename T>
C_& operator<<(C_& __m, const T& __s) {
  if (!1) cerr << "\E[91m" << __s << "\E[0m";
  return __m;
}
C_ merr;
struct __s {
  __s() {
    if (1) {
      ios_base::Init i;
      cin.sync_with_stdio(0);
      cin.tie(0);
    }
  }
  ~__s() {
    merr << "Execution time: " << (double)clock() / CLOCKS_PER_SEC << " s.\n";
  }
} __S;
vector<int> TL[1111111];
vector<int> MN[1111111];
int A[500055];
int L[500055];
vector<int> I[500055];
map<int, int> mp;
int mlen;
int getidx(int x) {
  if (mp.find(x) == mp.end()) {
    mp[x] = mlen++;
  }
  return mp[x];
}
inline int myless1_l(int a, int b) { return (a - L[a]) < (b - L[b]); }
inline void merge_l(vector<int>& to, const vector<int>& v1,
                    const vector<int> v2) {
  int i = 0, j = 0;
  int sz1 = (int)v1.size(), sz2 = (int)v2.size();
  int idx = 0;
  while (i < sz1 || j < sz2) {
    if (i < sz1 && (j >= sz2 || myless1_l(v1[i], v2[j]))) {
      to[idx++] = (v1[i++]);
    } else {
      to[idx++] = (v2[j++]);
    }
  }
}
void build_l(int v, int tl, int tr) {
  if (tl == tr) {
    TL[v].push_back(tl);
    MN[v].push_back(L[tl]);
  } else {
    int mm = (tl + tr) / 2;
    build_l(v * 2 + 1, tl, mm);
    build_l(v * 2 + 2, mm + 1, tr);
    TL[v].resize(TL[v * 2 + 1].size() + TL[v * 2 + 2].size());
    merge_l(TL[v], TL[v * 2 + 1], TL[v * 2 + 2]);
    int mn = 1000000000;
    MN[v].resize(TL[v].size());
    for (int i = (int)MN[v].size() - 1; i >= 0; i--) {
      if (L[TL[v][i]] < mn) mn = L[TL[v][i]];
      MN[v][i] = mn;
    }
  }
}
inline int val(int x) { return x - L[x]; }
int query_l(int v, int tl, int tr, int l, int r, int lll) {
  if (l > r) return 1000000000;
  if (tl == l && tr == r) {
    if (val(TL[v].back()) < lll) return 1000000000;
    int ll = 0, rr = (int)TL[v].size() - 1;
    while (ll < rr) {
      int mm = (ll + rr) / 2;
      if (val(TL[v][mm]) < lll) {
        ll = mm + 1;
      } else {
        rr = mm;
      }
    }
    return MN[v][ll];
  }
  int mm = (tl + tr) / 2;
  int q1 = query_l(v * 2 + 1, tl, mm, l, ((mm) <= (r) ? (mm) : (r)), lll);
  int q2 = query_l(v * 2 + 2, mm + 1, tr, ((mm + 1) >= (l) ? (mm + 1) : (l)), r,
                   lll);
  return ((q1) <= (q2) ? (q1) : (q2));
}
int n, m;
inline int query(int l, int r) {
  int ql = query_l(0, 0, n - 1, l, r, l);
  if (ql >= 1000000000) return -1;
  return ql;
}
int main(void) {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    A[i] = getidx(a);
    I[A[i]].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    int a = A[i];
    vector<int>::iterator it;
    if (I[a][0] == i) {
      L[i] = 1000000000;
    } else {
      it = lower_bound(I[a].begin(), I[a].end(), i);
      it--;
      L[i] = i - (*it);
    }
  }
  build_l(0, 0, n - 1);
  for (int i = 0; i < m; i++) {
    int l, r, q;
    cin >> l >> r;
    q = query(l - 1, r - 1);
    cout << q << '\n';
  }
  return 0;
}
