#include <bits/stdc++.h>
using namespace std;
int n, m;
int seg[500009 * 4];
int lef[500009];
map<int, int> last;
vector<int> g[500009];
int gir[500009];
int ask[500009];
void update(int v, int L, int R, int pos, int x) {
  if (L == R) {
    seg[v] = x;
    return;
  }
  int m = (L + R) / 2;
  if (pos <= m)
    update(v * 2, L, m, pos, x);
  else
    update(v * 2 + 1, m + 1, R, pos, x);
  seg[v] = min(seg[v * 2], seg[v * 2 + 1]);
}
int find(int k, int a, int b, int bas, int son) {
  if (bas <= a && b <= son) return seg[k];
  if (a > son || b < bas) return 1000000007;
  int o = (a + b) / 2;
  return min(find(k * 2, a, o, bas, son), find(k * 2 + 1, o + 1, b, bas, son));
}
int main() {
  ios_base::sync_with_stdio(false);
  register int x, y, s;
  cin >> n >> m;
  for (int i = 0; i < n * 4; i++) seg[i] = 1000000007;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    lef[i] = last[x];
    last[x] = i;
  }
  for (int i = 1; i <= m; i++) {
    cin >> ask[i] >> y;
    g[y].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (lef[i]) update(1, 1, n, lef[i], i - lef[i]);
    for (int j = 0; j < g[i].size(); j++) {
      s = g[i][j];
      gir[s] = find(1, 1, n, ask[s], i);
      if (gir[s] >= 1000000007) gir[s] = -1;
    }
  }
  for (int i = 1; i <= m; i++) cout << gir[i] << "\n";
  return 0;
}
