#include <bits/stdc++.h>
using namespace std;
int const N = 5e5 + 20, INF = 1e9;
int n, m, a[N], val[N << 2], mn[N << 2], ans[N];
pair<int, int> q[N];
vector<int> v[N];
map<int, int> last;
void build(int v = 1, int b = 0, int e = n) {
  if (b == e - 1) {
    val[v] = INF;
    mn[v] = INF;
    return;
  }
  int mid = b + e >> 1, lc = v << 1, rc = lc | 1;
  build(lc, b, mid);
  build(rc, mid, e);
  val[v] = INF;
  mn[v] = min(mn[lc], mn[rc]);
  return;
}
int get(int l, int r, int v = 1, int b = 0, int e = n) {
  mn[v] = min(mn[v], val[v]);
  if (l >= e || r <= b) return INF;
  if (l <= b && e <= r) return mn[v];
  int mid = b + e >> 1, lc = v << 1, rc = lc | 1;
  val[lc] = min(val[lc], val[v]), val[rc] = min(val[rc], val[v]);
  int ret = min(get(l, r, lc, b, mid), get(l, r, rc, mid, e));
  return ret;
}
void update(int l, int r, int x, int v = 1, int b = 0, int e = n) {
  mn[v] = min(mn[v], val[v]);
  if (l >= e || r <= b) return;
  mn[v] = min(mn[v], x);
  if (l <= b && e <= r) {
    val[v] = min(val[v], x);
    return;
  }
  int mid = b + e >> 1, lc = v << 1, rc = lc | 1;
  val[lc] = min(val[lc], val[v]), val[rc] = min(val[rc], val[v]);
  update(l, r, x, lc, b, mid);
  update(l, r, x, rc, mid, e);
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) {
    cin >> q[i].first >> q[i].second;
    q[i].first--, q[i].second--;
    v[q[i].second].push_back(i);
  }
  build();
  for (int i = 0; i < n; i++) {
    if (last.count(a[i])) update(last[a[i]], last[a[i]] + 1, i - last[a[i]]);
    last[a[i]] = i;
    for (auto ind : v[i]) ans[ind] = get(q[ind].first, i);
  }
  for (int i = 0; i < m; i++) cout << (ans[i] == INF ? -1 : ans[i]) << '\n';
  return 0;
}
