#include <bits/stdc++.h>
using namespace std;
const int MAXN = 600000;
int n, m, kil;
int pre[MAXN], a[MAXN];
map<int, int> re;
vector<pair<int, int> > q[MAXN];
int ans[MAXN];
int st[MAXN], id[MAXN], top;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  re.clear();
  for (int i = 1; i <= n; i++) {
    pre[i] = re[a[i]];
    if (pre[i] == 0) pre[i] = -MAXN;
    re[a[i]] = i;
  }
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    q[r].push_back(make_pair(l, i));
  }
  top = 0;
  st[0] = -1;
  id[0] = -1;
  for (int i = 1; i <= n; i++) {
    int d = i - pre[i];
    top++;
    while (st[top - 1] >= d) top--;
    if (id[top - 1] > pre[i]) {
      top--;
    } else {
      st[top] = d;
      id[top] = pre[i];
    }
    for (int j = q[i].size() - 1; j >= 0; j--) {
      int& l = q[i][j].first;
      if (l > id[top])
        ans[q[i][j].second] = -1;
      else {
        int now = (int)(lower_bound(id, id + top + 1, l) - id);
        ans[q[i][j].second] = st[now];
      }
    }
  }
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}
