#include <bits/stdc++.h>
using namespace std;
const int N = (int)5E5 + 5;
int MOD = (int)1E9 + 7;
namespace NUM {
int primes[1000005];
int visited[1000005];
vector<int> vp;
void getAllPrimes() {
  for (int i = 2; i <= 1000000; i++) {
    if (!visited[i]) {
      primes[i] = 1;
      vp.push_back(i);
      for (int j = 2 * i; j <= 1000000; j += i) {
        visited[j] = 1;
      }
    }
  }
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
void exgcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return;
  }
  exgcd(b, (a % b + b) % b, y, x);
  y -= a / b * x;
}
long long powmod(long long x, long long n, long long m) {
  if (n == 0) return 1;
  return n % 2 == 0 ? powmod(x * x % m, n / 2, m)
                    : x * powmod(x * x % m, n / 2, m) % m;
}
long long block_divide_sum(int x, int s, int e) {
  long long ans = 0;
  for (int i = s; i <= e; i++) {
    int val = x / i;
    int j = min(e, x / val);
    ans += val * (j - i + 1);
    i = j;
  }
  return ans;
}
}  // namespace NUM
using namespace NUM;
namespace TP {
struct tp {
  int i;
  int j;
  int k;
  tp() {}
  tp(int i, int j, int k) : i(i), j(j), k(k) {}
  bool operator==(const tp &rhs) const {
    return i == rhs.i && j == rhs.j && k == rhs.k;
  }
  bool operator!=(const tp &rhs) const { return !(rhs == *this); }
};
struct hashtp {
  size_t operator()(const tp &t) const {
    return hash<int>()(t.i) + hash<int>()(t.j) + hash<int>()(t.k);
  }
};
}  // namespace TP
using namespace TP;
namespace ST {
struct snode {
  int s;
  int e;
  snode *l;
  snode *r;
  int lazy;
  int minn;
};
snode *build(int s, int e) {
  if (s == e) return new snode{s, e, 0, 0, 0, 2 * N};
  int m = (s + e) / 2;
  snode *l = build(s, m);
  snode *r = build(m + 1, e);
  return new snode{s, e, l, r, 0, 2 * N};
}
void pushdown(snode *root) {
  if (root->lazy == 0) return;
  root->l->minn = root->lazy;
  root->r->minn = root->lazy;
  root->l->lazy = root->lazy;
  root->r->lazy = root->lazy;
  root->lazy = 0;
}
void pushup(snode *root) { root->minn = min(root->l->minn, root->r->minn); }
void update(snode *root, int s, int e, int val) {
  if (s == root->s && e == root->e) {
    root->minn = val;
    root->lazy = val;
    return;
  }
  pushdown(root);
  int m = root->s + root->e >> 1;
  if (e <= m) {
    update(root->l, s, e, val);
  } else if (s >= m + 1) {
    update(root->r, s, e, val);
  } else {
    update(root->l, s, m, val);
    update(root->r, m + 1, e, val);
  }
  pushup(root);
}
int query(snode *root, int s, int e) {
  if (s == root->s && e == root->e) {
    return root->minn;
  }
  pushdown(root);
  int m = root->s + root->e >> 1;
  if (e <= m) {
    return query(root->l, s, e);
  } else if (s >= m + 1) {
    return query(root->r, s, e);
  } else {
    return min(query(root->l, s, m), query(root->r, m + 1, e));
  }
}
void rebuild(snode *root, int *p) {
  root->lazy = 0;
  if (root->s == root->e) {
    return;
  }
  rebuild(root->l, p);
  rebuild(root->r, p);
  pushup(root);
}
};  // namespace ST
using namespace ST;
namespace UF {
struct unode {
  int p;
};
int getpa() {}
void merge() {}
}  // namespace UF
using namespace UF;
struct mat {
  int temp[2][2];
  mat() {}
  mat(int a, int b, int c, int d) {
    temp[0][0] = a;
    temp[0][1] = b;
    temp[1][0] = c;
    temp[1][1] = d;
  }
  mat operator*(mat m) {
    mat res;
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        int sum = 0;
        for (int k = 0; k < 2; k++) {
          sum += (1LL * temp[i][k] * m.temp[k][j]);
        }
        res.temp[i][j] = sum;
      }
    }
    return res;
  }
};
int arr[N];
int bef[N];
int beh[N];
unordered_map<int, int> last;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > qs;
  for (int i = 0; i < N; i++) {
    beh[i] = -1;
    bef[i] = -1;
  }
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (last.count(arr[i])) {
      bef[i] = i - last[arr[i]];
      beh[last[arr[i]]] = bef[i];
    }
    last[arr[i]] = i;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    qs.push_back(pair<int, int>(a, b));
  }
  vector<pair<int, int> > copy = qs;
  map<long long, int> mapp;
  sort(copy.begin(), copy.end());
  snode *root = build(0, n - 1);
  for (int i = 0; i < n; i++) {
    if (bef[i] > 0) {
      update(root, i, i, bef[i]);
    }
  }
  int i = 0;
  for (pair<int, int> p : copy) {
    int a = p.first - 1;
    int b = p.second - 1;
    while (i < a) {
      if (beh[i] > 0) {
        update(root, i + beh[i], i + beh[i], 2 * N);
      }
      i++;
    }
    int ans = query(root, a, b);
    if (ans < N) {
      mapp[(long long)a * N + b] = ans;
    } else {
      mapp[(long long)a * N + b] = -1;
    }
  }
  for (pair<int, int> p : qs) {
    cout << mapp[(long long)(p.first - 1) * N + (p.second - 1)] << endl;
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  solve();
  return 0;
}
