#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
int n, m;
vector<int> arr, t, ans;
vector<pair<pair<int, int>, int> > req;
map<int, int> mp;
void update(int v, int tl, int tr, int pos, int add) {
  if (tl == tr) {
    t[v] = add;
  } else {
    int tm = (tl + tr) >> 1;
    if (pos <= tm) {
      update(2 * v + 1, tl, tm, pos, add);
    } else {
      update(2 * v + 2, tm + 1, tr, pos, add);
    }
    t[v] = min(t[2 * v + 1], t[2 * v + 2]);
  }
}
int get(int v, int tl, int tr, int l, int r) {
  if (l > r) {
    return INF;
  }
  if (tl == l && tr == r) {
    return t[v];
  } else {
    int tm = (tl + tr) >> 1;
    return min(get(2 * v + 1, tl, tm, l, min(tm, r)),
               get(2 * v + 2, tm + 1, tr, max(tm + 1, l), r));
  }
}
bool cmp(const pair<pair<int, int>, int> &a,
         const pair<pair<int, int>, int> &b) {
  return a.first.first > b.first.first;
}
int main() {
  scanf("%d%d", &n, &m);
  arr.resize(n);
  t.resize(4 * n, INF);
  ans.resize(m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &arr[i]);
  }
  for (int i = n - 1; i >= 0; --i) {
    int q = mp[arr[i]], a = arr[i];
    if (!q) {
      arr[i] = -1;
    } else {
      arr[i] = q;
    }
    mp[a] = i;
  }
  req.resize(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &req[i].first.first, &req[i].first.second);
    req[i].first.first--;
    req[i].first.second--;
    req[i].second = i;
  }
  sort(req.begin(), req.end(), cmp);
  for (int i = 0, l = n - 1; i < m; ++i) {
    while (l >= req[i].first.first) {
      if (arr[l] != -1) {
        int dist = arr[l] - l;
        update(0, 0, n - 1, arr[l], dist);
      }
      --l;
    }
    int dist = get(0, 0, n - 1, req[i].first.first, req[i].first.second);
    if (dist != INF) {
      ans[req[i].second] = dist;
    } else {
      ans[req[i].second] = -1;
    }
  }
  for (int i = 0; i < m; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
