#include <bits/stdc++.h>
using namespace std;
const int INF = 12345678;
const int MAXN = 5000001;
int a[MAXN];
pair<int, int> f[MAXN];
int bl[MAXN];
vector<pair<int, int> > otr;
vector<pair<int, int> > anss;
int p[MAXN];
int t[4 * MAXN];
int dlin[MAXN];
void built(int v, int l, int r) {
  if (l == r) {
    t[v] = dlin[l];
  } else {
    int mid = (l + r) / 2;
    built(v * 2, l, mid);
    built(v * 2 + 1, mid + 1, r);
    t[v] = min(t[v * 2], t[v * 2 + 1]);
  }
}
int mn(int v, int tl, int tr, int l, int r) {
  if (l > r) {
    return 123456789;
  }
  if (l == tl && r == tr) {
    return t[v];
  }
  int mid = (tl + tr) / 2;
  return min(mn(v * 2, tl, mid, l, min(r, mid)),
             mn(v * 2 + 1, mid + 1, tr, max(mid + 1, l), r));
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    f[i] = make_pair(a[i], i);
  }
  sort(f + 1, f + n + 1);
  for (int i = 1; i <= n - 1; ++i) {
    if (f[i].first == f[i + 1].first) {
      bl[f[i].second] = f[i + 1].second;
    } else {
      bl[f[i].second] = INF;
    }
  }
  bl[f[n].second] = INF;
  for (int i = 1; i <= n - 1; ++i) {
    if (bl[i] != INF) {
      otr.push_back(make_pair(i, bl[i]));
    }
  }
  if (otr.size() == 0) {
    for (int i = 1; i <= m; ++i) {
      cout << -1 << endl;
    }
    return 0;
  }
  sort(otr.begin(), otr.end());
  for (int i = 0; i < otr.size() - 1; ++i) {
    if (otr[i].second >= otr[i + 1].second) {
      p[i] = 0;
    }
  }
  int sr = otr.size() - 1;
  for (int i = otr.size() - 2; i >= 0; --i) {
    if (otr[i].second >= otr[sr].second) {
      p[i] = 1;
    } else {
      sr = i;
    }
  }
  for (int i = 0; i < otr.size(); ++i) {
    if (!p[i]) {
      anss.push_back(otr[i]);
    }
  }
  for (int i = 0; i < anss.size(); ++i) {
    dlin[i + 1] = anss[i].second - anss[i].first;
  }
  built(1, 1, anss.size());
  for (int i = 1; i <= m; ++i) {
    int l, r;
    cin >> l >> r;
    int ll, rr;
    int bot = -1;
    int top = anss.size();
    while (top > bot + 1) {
      int mid = (top + bot) / 2;
      if (anss[mid].first >= l) {
        top = mid;
      } else {
        bot = mid;
      }
    }
    if (top == anss.size()) {
      cout << -1 << endl;
      continue;
    }
    if (anss[top].second > r) {
      cout << -1 << endl;
      continue;
    }
    ll = top + 1;
    bot = -1;
    top = anss.size();
    while (top > bot + 1) {
      int mid = (top + bot) / 2;
      if (anss[mid].second > r) {
        top = mid;
      } else {
        bot = mid;
      }
    }
    if (bot == -1) {
      cout << -1 << endl;
      continue;
    }
    if (anss[bot].first < l) {
      cout << -1 << endl;
      continue;
    }
    rr = bot + 1;
    cout << mn(1, 1, anss.size(), ll, rr) << endl;
  }
}
