#include <bits/stdc++.h>
using namespace std;
int a[500001], b[500001], d[500001];
map<int, int> la;
vector<pair<int, int> > c;
int p[1000][1000];
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 0; i < n; i++) {
    int aa;
    scanf("%d", &aa);
    b[i] = (la[aa] ? i + 1 - la[aa] : 1000000);
    la[aa] = i + 1;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (b[i] != 1000000) {
      c.push_back(make_pair(i - b[i], i));
    }
  }
  for (int i = 0; i < c.size(); i++) {
    a[c[i].first] = c[i].second;
    d[c[i].second] = c[i].first + 1;
  }
  int len = 0;
  for (; len * len < n; len++)
    ;
  for (int i = 0; i < 1000; i++) {
    for (int j = 0; j < 1000; j++) {
      p[i][j] = 1000000;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i]) {
      p[a[i] / len - i / len][i / len] =
          min(p[a[i] / len - i / len][i / len], a[i] - i);
    }
  }
  for (int i = 1; i < len; i++) {
    for (int j = 0; j < len - i; j++) {
      p[i][j] = min(p[i][j], p[i - 1][j]);
      p[i][j] = min(p[i][j], p[i - 1][j + 1]);
    }
  }
  for (int rr = 0; rr < m; rr++) {
    int l, r;
    scanf("%d", &l);
    scanf("%d", &r);
    l--;
    int lc = (l % len == 0 ? l : (l / len + 1) * len);
    int rc = (r % len == 0 ? r : r - r % len);
    int ans = 1000000;
    if (lc >= rc) {
      for (int i = l; i < r; i++) {
        if (a[i] && a[i] < r) {
          ans = min(ans, a[i] - i);
        }
      }
    } else {
      for (int i = l; i < lc; i++) {
        if (a[i] && a[i] < r) {
          ans = min(ans, a[i] - i);
        }
      }
      ans = min(ans, p[(rc - lc) / len - 1][lc / len]);
      for (int i = r - 1; i >= rc; i--) {
        if (d[i] && d[i] - 1 >= l) {
          ans = min(ans, i - d[i] + 1);
        }
      }
    }
    if (ans == 1000000)
      printf("-1\n");
    else
      printf("%d\n", ans);
  }
  return 0;
}
