#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5, inf = 1e17;
long long n, m, a[N + 5], f[N + 5], ans[N + 5], l, r;
map<int, int> pos;
vector<pair<int, int> > g[N + 5];
inline void update(int pos, long long x) {
  for (; pos >= 1; pos = (pos & (pos + 1)) - 1) {
    f[pos] = min(f[pos], x);
  }
}
inline long long get_min(int pos) {
  long long ans = 1e17;
  for (; pos <= n; pos |= pos + 1) {
    ans = min(ans, f[pos]);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= N; i++) {
    f[i] = inf;
  }
  for (int i = 1; i <= m; i++) {
    cin >> l >> r;
    g[r].push_back(make_pair(i, l));
  }
  for (int i = 1; i <= n; i++) {
    if (pos[a[i]]) {
      update(pos[a[i]], i - pos[a[i]]);
    }
    for (int j = 0; j < g[i].size(); j++) {
      long long x = get_min(g[i][j].second);
      if (x == 1e17) {
        x = -1;
      }
      ans[g[i][j].first] = x;
    }
    pos[a[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << "\n";
  }
}
