#include <bits/stdc++.h>
using namespace std;
struct query {
  int a, b;
  int id;
  int ans;
} querys[500010];
int n, m;
int num[500010], val[500010 * 4], pos[500010];
map<int, int> mp;
int cmp(struct query x, struct query y) { return x.b < y.b; }
int cmp1(struct query x, struct query y) { return x.id < y.id; }
void update(int id, int left, int right, int pos, int v) {
  if (left == right) {
    val[id] = v;
    return;
  }
  int mid = (left + right) >> 1;
  if (mid >= pos) {
    update(id << 1, left, mid, pos, v);
  } else {
    update((id << 1) | 1, mid + 1, right, pos, v);
  }
  val[id] = min(val[id << 1], val[(id << 1) | 1]);
}
int Query(int id, int left, int right, int le, int ri) {
  if (left == le && right == ri) {
    return val[id];
  }
  int mid = (left + right) >> 1;
  if (mid >= ri) {
    return Query(id << 1, left, mid, le, ri);
  } else if (mid < le) {
    return Query((id << 1) | 1, mid + 1, right, le, ri);
  } else {
    return min(Query(id << 1, left, mid, le, mid),
               Query((id << 1) | 1, mid + 1, right, mid + 1, ri));
  }
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &num[i]);
    }
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &querys[i].a, &querys[i].b);
      querys[i].id = i;
    }
    sort(querys, querys + m, cmp);
    for (int i = 0; i <= n * 4; i++) {
      val[i] = 99999999;
    }
    int start = 1;
    int cou = 1;
    for (int i = 0; i < m; i++) {
      while (start <= querys[i].b) {
        if (mp.find(num[start]) != mp.end()) {
          int re = mp[num[start]];
          update(1, 1, n, pos[re], start - pos[re]);
          pos[re] = start;
        } else {
          mp[num[start]] = cou;
          pos[cou++] = start;
        }
        start++;
      }
      querys[i].ans = Query(1, 1, n, querys[i].a, querys[i].b);
      if (querys[i].ans == 99999999) {
        querys[i].ans = -1;
      }
    }
    sort(querys, querys + m, cmp1);
    for (int i = 0; i < m; i++) {
      printf("%d\n", querys[i].ans);
    }
  }
  return 0;
}
