#include <bits/stdc++.h>
struct istream {
  int c, f;
  template <typename T>
  inline istream& operator>>(T& d) {
    for (f = 0; !isdigit(c = getchar()); f = c == '-')
      ;
    for (d = 0; isdigit(c); c = getchar()) d = d * 10 + (c ^ '0');
    if (f) d = -d;
    return *this;
  }
} cin;
struct asks {
  int l, r, id;
  inline bool operator<(const asks& rhs) const { return r < rhs.r; }
} q[500005];
std::unordered_map<int, int> pre;
int n, m, a[500005];
unsigned d[500005 << 2], ans[500005];
void modify(int l, int r, int o, const int& pos, const unsigned& val) {
  if (l == r)
    d[o] = val;
  else {
    const int mid = l + r >> 1;
    if (pos <= mid)
      modify(l, mid, o << 1, pos, val);
    else
      modify(mid + 1, r, o << 1 | 1, pos, val);
    d[o] = std::min(d[o], val);
  }
}
unsigned query(int l, int r, int o, const int& L, const int& R) {
  if (L <= l && r <= R) return d[o];
  const int mid = l + r >> 1;
  if (L <= mid && mid < R)
    return std::min(query(l, mid, o << 1, L, R),
                    query(mid + 1, r, o << 1 | 1, L, R));
  if (L <= mid) return query(l, mid, o << 1, L, R);
  return query(mid + 1, r, o << 1 | 1, L, R);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  memset(d, -1, sizeof d);
  for (int i = 1; i <= m; ++i) cin >> q[q[i].id = i].l >> q[i].r;
  std::sort(q + 1, q + m + 1);
  for (int R = 0, i = 1; i <= m; ++i) {
    while (R < q[i].r) {
      if (pre.count(a[++R])) {
        const int p = pre[a[R]];
        modify(1, n, 1, p, R - p);
      }
      pre[a[R]] = R;
    }
    ans[q[i].id] = query(1, n, 1, q[i].l, R);
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
  return 0;
}
