#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int arr[N];
vector<pair<int, int> > v[N];
int ans[N];
int n, m;
int bit[N];
int segtree[4 * N];
int lazy[4 * N];
map<int, int> last;
void push(int l, int r, int node) {
  if (lazy[node]) {
    segtree[node] = min(lazy[node], segtree[node]);
    if (l != r) {
      lazy[node + node] = lazy[node];
      lazy[node + node + 1] = lazy[node];
    }
    lazy[node] = 0;
  }
}
void update(int l, int r, int node, int ql, int qr, int val) {
  push(l, r, node);
  if (l > qr || r < ql) {
    return;
  }
  if (l >= ql && r <= qr) {
    lazy[node] = val;
    push(l, r, node);
    return;
  }
  int mid = l + r >> 1;
  update(l, mid, node + node, ql, qr, val);
  update(mid + 1, r, node + node + 1, ql, qr, val);
  segtree[node] = min(segtree[node + node], segtree[node + node + 1]);
}
long long query(int l, int r, int node, int ql, int qr) {
  push(l, r, node);
  if (l > qr || r < ql) {
    return n + 1;
  }
  if (l >= ql && r <= qr) {
    return segtree[node];
  }
  int mid = l + r >> 1;
  return min(query(l, mid, node + node, ql, qr),
             query(mid + 1, r, node + node + 1, ql, qr));
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= 4 * n; i++) segtree[i] = n + 1;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    v[y].push_back(make_pair(x, i));
  }
  for (int i = 1; i <= n; i++) {
    if (last.find(arr[i]) != last.end())
      update(1, n, 1, last[arr[i]], last[arr[i]], i - last[arr[i]]);
    last[arr[i]] = i;
    int x = v[i].size();
    for (int j = 0; j < x; j++) {
      ans[v[i][j].second] = query(1, n, 1, v[i][j].first, i);
    }
  }
  for (int i = 1; i <= m; i++) {
    printf("%d\n", (ans[i] == n + 1) ? -1 : ans[i]);
  }
  return 0;
}
