#include <bits/stdc++.h>
using namespace std;
const int N = 1200000;
const int INF = 1000000007;
struct Tree {
  int x, u;
  bool f;
};
int n, m, a[N], ans[N], r, l, pr, k;
pair<int, int> q[N];
pair<int, int> pp;
map<pair<int, int>, int> p;
map<int, int> mm;
vector<pair<int, int> > u[N];
Tree tr[N];
void push(int i) {
  if (tr[i].f) {
    if (tr[i * 2].u > tr[i].u) {
      tr[i * 2].u = tr[i].u;
      tr[i * 2].x = tr[i].x;
      tr[i * 2].f = true;
    }
    if (tr[i * 2 + 1].u > tr[i].u) {
      tr[i * 2 + 1].x = tr[i].x;
      tr[i * 2 + 1].u = tr[i].u;
      tr[i * 2 + 1].f = true;
    }
    tr[i].f = false;
  }
}
void update(int x, int y, int i, int l, int r, int z) {
  if (r < x || y < l) return;
  if (x <= l && r <= y) {
    if ((!tr[i].f) || (tr[i].f && tr[i].x > z)) {
      tr[i].x = z;
      tr[i].u = z;
      tr[i].f = true;
    }
    return;
  }
  push(i);
  update(x, y, i * 2, l, (l + r) / 2, z);
  update(x, y, i * 2 + 1, (l + r) / 2 + 1, r, z);
  tr[i].x = min(tr[i * 2].x, tr[i * 2 + 1].x);
}
void RMQ(int x, int y, int i, int l, int r, int &z) {
  if (r < x || y < l) return;
  if (x <= l && r <= y) {
    z = min(z, tr[i].x);
    return;
  }
  push(i);
  RMQ(x, y, i * 2, l, (l + r) / 2, z);
  RMQ(x, y, i * 2 + 1, (l + r) / 2 + 1, r, z);
  tr[i].x = min(tr[i * 2].x, tr[i * 2 + 1].x);
}
int main() {
  scanf("%d %d", &n, &m);
  k = 1;
  while (k < m) k = k * 2;
  for (int i = 1; i <= k * 2 - 1; i++) {
    tr[i].x = INF;
    tr[i].u = INF;
  }
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &l, &r);
    q[i] = make_pair(l, r);
    u[r].push_back(make_pair(l, i));
  }
  sort(q, q + m);
  for (int i = 0; i < m; i++) p[make_pair(q[i].first, q[i].second)] = i + 1;
  for (int i = 1; i <= n; i++) {
    if (mm[a[i]] == 0)
      mm[a[i]] = i;
    else {
      int j = pr;
      while (j < m && q[j].first <= mm[a[i]]) j++;
      update(1, j, 1, 1, k, i - mm[a[i]]);
      pr = j;
      mm[a[i]] = i;
    }
    if (u[i].size() > 0) {
      for (int j = 0; j < u[i].size(); j++) {
        pp = make_pair(u[i][j].first, i);
        r = INF;
        RMQ(p[pp], p[pp], 1, 1, k, r);
        if (r == INF)
          ans[u[i][j].second] = -1;
        else
          ans[u[i][j].second] = r;
      }
    }
  }
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
}
