#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:500000000")
using namespace std;
const int INF = 2e9;
const int N = 5e5;
int a[N + 5], res[N + 5], minL[N + 5], maxR[N + 5], tmpMinL[N + 5];
int s;
struct query {
  int l, r, num, c_l;
  query() {}
  query(int _l, int _r, int _num) {
    l = _l;
    r = _r;
    num = _num;
  }
  const bool operator<(query other) const {
    if (c_l == other.c_l) {
      return r < other.r;
    }
    return c_l < other.c_l;
  }
} q[N + 5];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  map<int, int> compressed;
  int newValue = 1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (compressed[a[i]] == 0) {
      compressed[a[i]] = newValue;
      ++newValue;
    }
    a[i] = compressed[a[i]];
  }
  s = sqrt((double)n) + 1;
  for (int i = 1; i <= m; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    q[i] = query(l, r, i);
    q[i].c_l = l / s;
  }
  sort(q + 1, q + m + 1);
  q[0] = query(-1, -2, 0);
  q[0].c_l = -1;
  int prevRes = INF;
  int l = -1;
  for (int i = 1; i <= m; ++i) {
    res[q[i].num] = INF;
    if (q[i - 1].c_l != q[i].c_l) {
      for (int j = l; j <= q[i - 1].r; j++) {
        minL[a[j]] = 0;
        maxR[a[j]] = 0;
      }
      prevRes = INF;
      l = (q[i].c_l + 1) * s;
      if (q[i].c_l == q[i].r / s) {
        for (int j = q[i].r; j >= q[i].l; j--) {
          if (tmpMinL[a[j]] != 0) {
            res[q[i].num] = min(res[q[i].num], tmpMinL[a[j]] - j);
          }
          tmpMinL[a[j]] = j;
        }
        for (int j = q[i].r; j >= q[i].l; j--) {
          tmpMinL[a[j]] = 0;
        }
      } else {
        for (int j = l; j <= q[i].r; j++) {
          if (minL[a[j]] == 0) {
            minL[a[j]] = j;
          } else {
            prevRes = min(prevRes, j - maxR[a[j]]);
          }
          maxR[a[j]] = j;
        }
        res[q[i].num] = prevRes;
        for (int j = l - 1; j >= q[i].l; j--) {
          if (tmpMinL[a[j]] != 0) {
            res[q[i].num] = min(res[q[i].num], tmpMinL[a[j]] - j);
          } else if (minL[a[j]] != 0) {
            res[q[i].num] = min(res[q[i].num], minL[a[j]] - j);
          }
          tmpMinL[a[j]] = j;
        }
        for (int j = l - 1; j >= q[i].l; j--) {
          tmpMinL[a[j]] = 0;
        }
      }
    } else {
      if (q[i].c_l == q[i].r / s) {
        for (int j = q[i].r; j >= q[i].l; j--) {
          if (tmpMinL[a[j]] != 0) {
            res[q[i].num] = min(res[q[i].num], tmpMinL[a[j]] - j);
          }
          tmpMinL[a[j]] = j;
        }
        for (int j = q[i].r; j >= q[i].l; j--) {
          tmpMinL[a[j]] = 0;
        }
      } else {
        for (int j = max(q[i - 1].r + 1, l); j <= q[i].r; j++) {
          if (minL[a[j]] == 0) {
            minL[a[j]] = j;
          } else {
            prevRes = min(j - maxR[a[j]], prevRes);
          }
          maxR[a[j]] = j;
        }
        res[q[i].num] = prevRes;
        for (int j = l - 1; j >= q[i].l; j--) {
          if (tmpMinL[a[j]] != 0) {
            res[q[i].num] = min(res[q[i].num], tmpMinL[a[j]] - j);
          } else if (minL[a[j]] != 0) {
            res[q[i].num] = min(res[q[i].num], minL[a[j]] - j);
          }
          tmpMinL[a[j]] = j;
        }
        for (int j = l - 1; j >= q[i].l; j--) {
          tmpMinL[a[j]] = 0;
        }
      }
    }
  }
  for (int i = 1; i <= m; ++i) {
    if (res[i] == INF) {
      printf("-1\n");
    } else {
      printf("%d\n", res[i]);
    }
  }
  return 0;
}
