#include <bits/stdc++.h>
using namespace std;
class segment_tree {
  vector<int> seg_min;
  int n;

 public:
  segment_tree(int n) {
    this->n = n;
    int number_of_nodes = n * (log2(n) + 3);
    seg_min.resize(number_of_nodes, 1 << 30);
  }
  void update(int pos, int val, int node, int st, int ed) {
    if (st == ed) {
      seg_min[node] = val;
    } else {
      int mid = (st + ed) / 2;
      if (pos <= mid) {
        update(pos, val, node * 2, st, mid);
      }
      if (mid < pos) {
        update(pos, val, node * 2 + 1, mid + 1, ed);
      }
      seg_min[node] = min(seg_min[node * 2], seg_min[node * 2 + 1]);
    }
  }
  void update(int pos, int val) { update(pos, val, 1, 1, n); }
  int get(int l, int r, int node, int st, int ed) {
    int ans = 1 << 30;
    if (st == ed) {
      ans = seg_min[node];
    } else if (l <= st && ed <= r) {
      ans = seg_min[node];
    } else {
      int mid = (st + ed) / 2;
      if (l <= mid) {
        ans = min(ans, get(l, r, node * 2, st, mid));
      }
      if (mid < r) {
        ans = min(ans, get(l, r, node * 2 + 1, mid + 1, ed));
      }
    }
    return ans;
  }
  int get(int l, int r) { return get(l, r, 1, 1, n); }
};
struct query {
  int st, ed, id, res;
  query() { st = ed = id = res = 0; }
  query(int _st, int _ed, int _id, int _res) {
    st = _st, ed = _ed, id = _ed, res = _res;
  }
};
bool comp1(const query &a, const query &b) {
  return (a.st == b.st) ? a.ed < b.ed : a.st < b.st;
}
bool comp2(const query &a, const query &b) { return a.id < b.id; }
map<int, vector<int> > mp;
vector<int> input;
vector<query> qu;
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  input.resize(n);
  segment_tree my_seg = segment_tree(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &input[i]);
    vector<int> &vec = mp[input[i]];
    if (vec.size()) {
      my_seg.update(i + 1, i - vec.back());
    }
    vec.push_back(i);
  }
  qu.resize(q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &qu[i].st, &qu[i].ed);
    qu[i].st--;
    qu[i].ed--;
    qu[i].id = i;
    qu[i].res = -1;
  }
  sort(qu.begin(), qu.end(), comp1);
  int idx = 0;
  for (int i = 0; i < q; i++) {
    int cur_st = qu[i].st;
    int cur_ed = qu[i].ed;
    for (; idx < cur_st; idx++) {
      vector<int> &vec = mp[input[idx]];
      int id = lower_bound(vec.begin(), vec.end(), idx) - vec.begin();
      id++;
      if (id != (int)vec.size()) {
        my_seg.update(vec[id] + 1, 1 << 30);
      }
    }
    int ans = my_seg.get(cur_st + 1, cur_ed + 1);
    qu[i].res = ans == (1 << 30) ? -1 : ans;
  }
  sort(qu.begin(), qu.end(), comp2);
  for (int i = 0; i < q; i++) {
    printf("%d\n", qu[i].res);
  }
}
