#include <bits/stdc++.h>
using namespace std;
struct A {
  int n;
  int z;
};
int myfunction(const void* i, const void* j) {
  const A* k = (const A*)i;
  const A* l = (const A*)j;
  if (k->z != l->z)
    return (k->z - l->z);
  else
    return (k->n - l->n);
}
int main() {
  int n, m;
  cin >> n;
  cin >> m;
  A* a = new A[n];
  A* b = new A[n];
  A* c = new A[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &(a[i].z));
    a[i].n = i + 1;
  }
  int x, y;
  qsort(a, n, sizeof(A), myfunction);
  int ch = 0;
  for (int i = 1; i < n; i++)
    if (a[i - 1].z == a[i].z) {
      b[ch].n = a[i - 1].n;
      b[ch].z = a[i].n;
      ch += 1;
    }
  if (ch == 0) {
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &x, &y);
      cout << -1 << "\n";
    }
  } else {
    qsort(b, ch, sizeof(A), myfunction);
    int ch1 = 0;
    c[0].n = b[0].n;
    c[0].z = b[0].z;
    for (int i = 1; i < ch; i++) {
      if (b[i].n > c[ch1].n) {
        ch1++;
        c[ch1].n = b[i].n;
        c[ch1].z = b[i].z;
      }
    }
    static int f[1000000][21];
    for (int i = 0; i <= ch1; i++) f[i][0] = c[i].z - c[i].n;
    int st = 1;
    for (int k = 1; st <= ch1; k++) {
      for (int i = 0; i + st <= ch1; i++)
        f[i][k] = min(f[i][k - 1], f[i + st][k - 1]);
      st = st * 2;
    }
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &x, &y);
      if (c[ch1].n < x) {
        cout << -1 << "\n";
        continue;
      }
      if (c[0].z > y) {
        cout << -1 << "\n";
        continue;
      }
      int k1 = 0;
      int k2 = ch1;
      int k = 0;
      while (k1 < k2 - 1) {
        k = (k1 + k2) / 2;
        if (c[k].n < x)
          k1 = k;
        else
          k2 = k;
      }
      if (c[k1].n < x)
        k = k2;
      else
        k = k1;
      int l1 = 0;
      int l2 = ch1;
      int l = 0;
      while (l1 < l2 - 1) {
        l = (l1 + l2) / 2;
        if (c[l].z < y)
          l1 = l;
        else
          l2 = l;
      }
      if (c[l2].z <= y)
        l = l2;
      else
        l = l1;
      if (l < k) {
        cout << -1 << "\n";
        continue;
      }
      if (l == k)
        cout << c[l].z - c[l].n << "\n";
      else {
        int lg2 = 1;
        int lg = 0;
        while (lg2 <= l - k + 1) {
          lg2 = lg2 * 2;
          lg = lg + 1;
        };
        lg2 = lg2 / 2;
        lg = lg - 1;
        cout << min(f[k][lg], f[l - lg2 + 1][lg]) << "\n";
      }
    }
  }
  cout.flush();
  return 0;
}
