#include <bits/stdc++.h>
using namespace std;
int const inf = 1e9 + 1007;
int const maxn = 2000000;
int tree[maxn];
int sz = 1;
void init(int n) {
  while (sz < n) sz *= 2;
  for (int i = 0; i < (int)(maxn); ++i) tree[i] = inf;
}
void add(int index, int val) {
  index += sz;
  tree[index] = val;
  for (index >>= 1; index > 0; index >>= 1)
    tree[index] = min(tree[2 * index], tree[2 * index + 1]);
}
int get(int left, int right) {
  int ans = inf;
  for (left += sz, right += sz; left <= right;
       left = (left + 1) >> 1, right = (right - 1) >> 1) {
    if (left & 1) ans = min(ans, tree[left]);
    if (!(right & 1)) ans = min(ans, tree[right]);
  }
  return ans;
}
struct Query {
  int left;
  int right;
  int index;
};
Query q[maxn];
bool operator<(Query const& a, Query const& b) {
  return make_pair(a.right, a.left) < make_pair(b.right, b.left);
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < (int)(n); ++i) cin >> a[i];
  init(n);
  for (int i = 0; i < (int)(m); ++i) {
    cin >> q[i].left >> q[i].right;
    q[i].index = i;
  }
  sort(q, q + m);
  map<int, int> last_index;
  int qindex = 0;
  vector<int> ans(m, -1);
  for (int i = 0; i < (int)(n); ++i) {
    auto it = last_index.find(a[i]);
    if (it != last_index.end()) add(it->second, i - it->second);
    last_index[a[i]] = i;
    while (qindex < m && q[qindex].right == i + 1) {
      ans[q[qindex].index] = get(q[qindex].left - 1, q[qindex].right - 1);
      ++qindex;
    }
  }
  for (int i = 0; i < (int)(m); ++i)
    cout << (ans[i] == inf ? -1 : ans[i]) << "\n";
  return 0;
}
