#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int dp[N][20], pre[N], s[N];
int mm[N];
void initRMQ(int n, int b[]) {
  mm[0] = -1;
  for (int i = 1; i <= n; i++) {
    mm[i] = ((i & (i - 1)) == 0) ? mm[i - 1] + 1 : mm[i - 1];
    dp[i][0] = b[i];
  }
  for (int j = 1; j <= mm[n]; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
}
int rmq(int x, int y) {
  int k = mm[y - x + 1];
  return min(dp[x][k], dp[y - (1 << k) + 1][k]);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (long long(i) = 1; (i) <= (n); (i)++) scanf("%d", &s[i]);
  map<int, int> vis;
  for (int i = n; i > 0; i--) {
    if (vis[s[i]])
      pre[i] = vis[s[i]] - i;
    else
      pre[i] = n + 1;
    vis[s[i]] = i;
  }
  initRMQ(n, pre);
  int l, r, t, res, len, L, R;
  while (m--) {
    scanf("%d%d", &l, &r);
    res = rmq(l, r);
    if (res > r - l)
      res = -1;
    else {
      while (res != rmq(l, r - res)) {
        res = max(res, rmq(l, r - res));
        if (res > r - l) {
          res = -1;
          break;
        }
      }
    }
    printf("%d\n", res);
  }
  return 0;
}
