#include <bits/stdc++.h>
using namespace std;
void replace_elem(vector<int> &tree, int ind, int elem) {
  int n = tree.size() / 2;
  ind += n;
  tree[ind] = elem;
  int parent = ind / 2;
  while (parent != 0) {
    tree[parent] = min(tree[2 * parent], tree[2 * parent + 1]);
    parent /= 2;
  }
}
int find_min(const vector<int> &tree, int l, int r) {
  int n = tree.size() / 2;
  l += n;
  r += n;
  int result = INT_MAX;
  while (l <= r) {
    if (l % 2 == 1) {
      result = min(result, tree[l]);
      ++l;
    }
    if (r % 2 == 0) {
      result = min(result, tree[r]);
      --r;
    }
    l /= 2;
    r /= 2;
  }
  return result;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  map<int, int> last_ind;
  vector<int> pred_dist(n, INT_MAX);
  vector<int> next_ind(n, INT_MAX);
  for (int i = 0; i < n; ++i) {
    int elem;
    cin >> elem;
    map<int, int>::iterator last = last_ind.find(elem);
    if (last != last_ind.end()) {
      next_ind[last->second] = i;
      pred_dist[i] = i - last->second;
    }
    last_ind[elem] = i;
  }
  last_ind.clear();
  n = (1 << ((int)log2(n - 1) + 1));
  pred_dist.resize(2 * n, INT_MAX);
  for (int i = 2 * n - 1; i >= n; --i) pred_dist[i] = pred_dist[i - n];
  for (int i = n - 1; i >= 1; --i)
    pred_dist[i] = min(pred_dist[2 * i], pred_dist[2 * i + 1]);
  pred_dist[0] = INT_MAX;
  list<pair<pair<int, int>, int> > requests;
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    pair<pair<int, int>, int> request;
    request.second = i;
    request.first.first = l - 1;
    request.first.second = r - 1;
    requests.push_back(request);
  }
  requests.sort();
  int l = requests.front().first.first;
  for (int i = 0; i < l; ++i) replace_elem(pred_dist, i, INT_MAX);
  list<pair<int, int> > answers;
  for (const pair<pair<int, int>, int> &request : requests) {
    int cur_l = request.first.first;
    int cur_r = request.first.second;
    for (; l < cur_l; ++l)
      if (next_ind[l] != INT_MAX) replace_elem(pred_dist, next_ind[l], INT_MAX);
    pair<int, int> answer;
    answer.first = request.second;
    answer.second = find_min(pred_dist, cur_l, cur_r);
    if (answer.second == INT_MAX) answer.second = -1;
    answers.push_back(answer);
  }
  answers.sort();
  for (const pair<int, int> &answer : answers) cout << answer.second << "\n";
  return 0;
}
