#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
class SegTree {
 public:
  SegTree(const std::vector<int>& data) {
    base = 1;
    while (base < data.size()) {
      base *= 2;
    }
    tree = std::vector<int>(base * 2 + 1, inf);
    for (int i = 0; i < data.size(); ++i) {
      tree[base + i] = data[i];
    }
    for (int i = base - 1; i > 0; --i) {
      tree[i] = min(tree[2 * i], tree[2 * i + 1]);
    }
  }
  int GetMin(int l, int r) { return getMin(1, l, r, 0, base); }

 private:
  int getMin(int u, int ql, int qr, int vl, int vr) {
    if (qr <= vl) {
      return inf;
    }
    if (ql >= vr) {
      return inf;
    }
    if (ql <= vl && vr <= qr) {
      return tree[u];
    } else {
      return min(getMin(2 * u, ql, qr, vl, (vl + vr) / 2),
                 getMin(2 * u + 1, ql, qr, (vl + vr) / 2, vr));
    }
  }
  std::vector<int> tree;
  int base;
};
int bins(int ql, int qr, SegTree& ltree, SegTree& rtree) {
  int bl = 0;
  int br = qr - ql;
  int prevres = 0;
  while (br != bl) {
    int bm = (br + bl) / 2;
    if (prevres != 0 && prevres != inf && prevres > bm) {
      bm = prevres;
    }
    int res = min(ltree.GetMin(ql + bm, qr), rtree.GetMin(ql, qr - bm));
    if (res <= bm || res == inf) {
      return res;
    } else {
      bl = bm + 1;
    }
    prevres = res;
  }
  return inf;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  std::vector<int> left(n), right(n), tmp(n);
  std::map<int, int> lmap, rmap;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &tmp[i]);
  }
  for (int i = 0; i < n; ++i) {
    if (lmap.find(tmp[i]) == lmap.end()) {
      left[i] = inf;
    } else {
      left[i] = i - lmap.find(tmp[i])->second;
    }
    lmap[tmp[i]] = i;
  }
  for (int i = n - 1; i >= 0; --i) {
    if (rmap.find(tmp[i]) == rmap.end()) {
      right[i] = inf;
    } else {
      right[i] = rmap.find(tmp[i])->second - i;
    }
    rmap[tmp[i]] = i;
  }
  SegTree ltree(left);
  SegTree rtree(right);
  int ql, qr;
  for (int t = 0; t < m; ++t) {
    scanf("%d %d", &ql, &qr);
    ql -= 1;
    int res = bins(ql, qr, ltree, rtree);
    if (res == inf) {
      printf("-1\n");
    } else {
      printf("%d\n", res);
    }
  }
  return 0;
}
