#include <bits/stdc++.h>
using namespace std;
vector<int> pri;
const int each = 800;
int n, m, a[500010], fr[500010], ba[500010], chan[500010], back[500010],
    tmpba[500010], nowl, nowr, s, ans, tmp, print[500010], belong[500010];
struct node {
  int l, r, ID;
} nodes[500010];
bool cmp(node one, node ano) {
  if (belong[one.l] ^ belong[ano.l])
    return belong[one.l] < belong[ano.l];
  else
    return one.r < ano.r;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    pri.push_back(a[i]);
    belong[i] = (i - 1) / each + 1;
  }
  sort(pri.begin(), pri.end());
  pri.erase(unique(pri.begin(), pri.end()), pri.end());
  s = pri.size();
  for (int i = 1; i <= n; ++i)
    a[i] = lower_bound(pri.begin(), pri.end(), a[i]) - pri.begin() + 1;
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d", &nodes[i].l, &nodes[i].r);
    nodes[i].ID = i;
  }
  sort(nodes + 1, nodes + 1 + m, cmp);
  for (int i = 1; i <= m; ++i) {
    if (belong[nodes[i].l] ^ belong[nodes[i - 1].l]) {
      nowl = belong[nodes[i].l] * each + 1;
      nowr = nowl - 1;
      for (int j = 1; j <= s; ++j) fr[j] = ba[j] = 0;
      ans = 1e9;
    }
    if (nodes[i].r - nodes[i].l + 1 <= each * 2) {
      tmp = 1e9;
      for (int j = nodes[i].l; j <= nodes[i].r; ++j) {
        if (tmpba[a[j]]) tmp = min(j - tmpba[a[j]], tmp);
        tmpba[a[j]] = j;
      }
      print[nodes[i].ID] = tmp;
      for (int j = nodes[i].l; j <= nodes[i].r; ++j) tmpba[a[j]] = 0;
    } else {
      while (nowr < nodes[i].r) {
        ++nowr;
        if (!fr[a[nowr]]) fr[a[nowr]] = nowr;
        if (ba[a[nowr]]) ans = min(nowr - ba[a[nowr]], ans);
        ba[a[nowr]] = nowr;
      }
      tmp = ans;
      while (nowl > nodes[i].l) {
        --nowl;
        if (fr[a[nowl]]) ans = min(fr[a[nowl]] - nowl, ans);
        if (!chan[a[nowl]]) {
          chan[a[nowl]] = 1;
          back[a[nowl]] = fr[a[nowl]];
        }
        fr[a[nowl]] = nowl;
      }
      print[nodes[i].ID] = ans;
      ans = tmp;
      while (nowl < belong[nodes[i].l] * each + 1) {
        if (chan[a[nowl]]) {
          chan[a[nowl]] = 0;
          fr[a[nowl]] = back[a[nowl]];
        }
        ++nowl;
      }
    }
  }
  for (int i = 1; i <= m; ++i) {
    if (print[i] != 1e9)
      printf("%d\n", print[i]);
    else
      printf("-1\n");
  }
  return 0;
}
