#include <bits/stdc++.h>
using namespace std;
const int inf = 2e+9 + 7;
struct ques {
  int l, r, num;
};
bool operator<(const ques &less, const ques &more) { return (less.r < more.r); }
void Ccompress(vector<int> &ans) {
  vector<int> a = ans;
  sort(a.begin(), a.end());
  vector<int> b(1, a[0]);
  for (int i = 1; i < (int)a.size(); ++i)
    if (a[i] != a[i - 1]) b.push_back(a[i]);
  for (int i = 0; i < (int)ans.size(); ++i) {
    int l = 0;
    int r = b.size();
    int m;
    while (l < r - 1) {
      m = (l + r) / 2;
      if (b[m] <= ans[i])
        l = m;
      else
        r = m;
    }
    ans[i] = l;
  }
}
const int MX = 2e+6;
struct Tree {
  bool newval;
  int nv;
  int mn;
  int mx;
  Tree() {}
  Tree(bool _newval, int _nv, int _mn, int _mx)
      : newval(_newval), nv(_nv), mn(_mn), mx(_mx) {}
};
Tree vs[MX];
int NN;
void init(int n) {
  NN = n;
  vs[1] = Tree(true, inf, inf, inf);
}
int getVal(int n, int v = 1, int l = 0, int r = NN - 1) {
  if (vs[v].newval) return vs[v].nv;
  if (l == r) return vs[l].mn;
  int m = (l + r) / 2;
  if (n <= m) return getVal(n, 2 * v, l, m);
  return getVal(n, 2 * v + 1, m + 1, r);
}
void assignVal(int n, int val, int v = 1, int l = 0, int r = NN - 1) {
  if (r <= n && vs[v].mn >= val) {
    vs[v].newval = true;
    vs[v].nv = val;
    vs[v].mn = val;
    vs[v].mx = val;
    return;
  }
  if (vs[v].mx <= val || l > n) return;
  if (vs[v].newval) {
    vs[2 * v].newval = true;
    vs[2 * v + 1].newval = true;
    vs[2 * v].nv = vs[v].nv;
    vs[2 * v + 1].nv = vs[v].nv;
    vs[2 * v].mn = vs[v].nv;
    vs[2 * v + 1].mn = vs[v].nv;
    vs[2 * v].mx = vs[v].nv;
    vs[2 * v + 1].mx = vs[v].nv;
    vs[v].newval = false;
  }
  int m = (l + r) / 2;
  assignVal(n, val, 2 * v, l, m);
  assignVal(n, val, 2 * v + 1, m + 1, r);
  vs[v].mn = min(vs[2 * v].mn, vs[2 * v + 1].mn);
  vs[v].mx = max(vs[2 * v].mx, vs[2 * v + 1].mx);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  Ccompress(a);
  vector<ques> q(m + 1);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &q[i].l, &q[i].r);
    q[i].l--;
    q[i].r--;
    q[i].num = i;
  }
  q[m].r = inf;
  sort(q.begin(), q.end());
  vector<int> ans(m, -228);
  vector<int> prev(n, -inf);
  vector<int> last(n, -inf);
  for (int i = 0; i < n; ++i) {
    prev[i] = last[a[i]];
    last[a[i]] = i;
  }
  init(n);
  int j = 0;
  for (int i = 0; i < n; ++i) {
    if (prev[i] != -inf) assignVal(prev[i], i - prev[i]);
    while (q[j].r == i) {
      ans[q[j].num] = getVal(q[j].l);
      j++;
    }
  }
  for (int i = 0; i < m; ++i) {
    assert(ans[i] != -228);
    printf("%d\n", (ans[i] == inf ? -1 : ans[i]));
  }
  return 0;
}
