#include <bits/stdc++.h>
long long mpow(long long a, long long n, long long mod) {
  long long ret = 1;
  long long b = a;
  while (n) {
    if (n & 1) ret = (ret * b) % mod;
    b = (b * b) % mod;
    n >>= 1;
  }
  return (long long)ret;
}
using namespace std;
map<int, int> was;
int nx[(int)(5e5 + 25)];
vector<pair<int, int> > Q[(int)(5e5 + 25)];
int a[(int)(5e5 + 25)], ans[(int)(5e5 + 25)];
int seg[4 * (int)(5e5 + 25)];
void update(int i, int l, int r, int x, int val) {
  if (x < l || x > r) {
    return;
  }
  if (l == r && x == l) {
    seg[i] = val;
    return;
  }
  int mid = (l + r) >> 1;
  update(2 * i, l, mid, x, val);
  update(2 * i + 1, mid + 1, r, x, val);
  seg[i] = min(seg[2 * i], seg[2 * i + 1]);
}
int query(int i, int l, int r, int ql, int qr) {
  if (r < ql || l > qr) {
    return INT_MAX;
  }
  if (ql <= l && r <= qr) {
    return seg[i];
  }
  int mid = (l + r) >> 1;
  return min(query(2 * i, l, mid, ql, qr),
             query(2 * i + 1, mid + 1, r, ql, qr));
}
void solve() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i <= 4 * n + 2; i++) {
    seg[i] = INT_MAX;
  }
  for (int i = n; i >= 1; i--) {
    nx[i] = -1;
    if (was.find(a[i]) == was.end()) {
    } else {
      nx[i] = was[a[i]];
    }
    was[a[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d", &x);
    scanf("%d", &y);
    Q[x].push_back(make_pair(y, i));
  }
  for (int i = n; i >= 1; i--) {
    if (nx[i] != -1) {
      update(1, 1, n, nx[i], nx[i] - i);
    }
    for (int j = 0; j < Q[i].size(); j++) {
      int tempR = Q[i][j].first;
      int idx = Q[i][j].second;
      int val = query(1, 1, n, i, tempR);
      if (val == INT_MAX) {
        ans[idx] = -1;
      } else {
        ans[idx] = val;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    printf("%d", ans[i]);
    printf("\n");
  }
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
