func_code_string: #include <bits/stdc++.h>   using namespace std;   mt19937 gen(chrono::system_clock::now().time_since_epoch().count());   const int M = 3e5 + 7;   const int N = 1e6 + 7;   int n, q, l, r, t[N * 4], ans[N], k, x, tn = 1;   map<int, vector<int> > p;   map<int, vector<pair<int, int> > > otr;   map<int, vector<pair<int, int> > > R;   void update(int v, int tl, int tr, int pos, int x) {     if (tr == tl + 1) {       t[v] = min(t[v], x);       return;     }     int mid = (tl + tr) / 2;     if (pos < mid)       update(v << 1, tl, mid, pos, x);     else       update((v << 1) + 1, mid, tr, pos, x);     t[v] = min(t[v << 1], t[(v << 1) + 1]);     return;   }   long long query(int v, int tl, int tr, int l, int r) {     if (r <= tl || tr <= l) return 1e9;     if (l <= tl && tr <= r) return t[v];     int mid = (tl + tr) / 2;     return min(query(v << 1, tl, mid, l, r), query((v << 1) + 1, mid, tr, l, r));   }   int query(int l, int r) { return query(1, 0, tn, l, r); }   void update(int pos, int x) {     update(1, 0, tn, pos, x);     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> q;     while (tn < N) tn <<= 1;     for (int i = 0; i < n; i++) {       cin >> x;       if (p[x].size()) otr[i].push_back({p[x].back(), i - p[x].back()});       p[x].push_back(i);     }     for (int i = 0; i < q; i++) {       cin >> l >> r;       l--;       r--;       R[r].push_back({l, i});     }     for (int i = 1; i < tn * 2; i++) t[i] = 1e9 + 7;     for (int i = 0; i < q; i++) ans[i] = 1e9 + 7;     for (int i = 1; i < N; i++) {       for (int j = 0; j < otr[i].size(); j++)         update(otr[i][j].first, otr[i][j].second);       for (int j = 0; j < R[i].size(); j++)         ans[R[i][j].second] = query(R[i][j].first, i + 1);     }     for (int i = 0; i < q; i++) cout << (ans[i] >= n * 2 ? -1 : ans[i]) <<   n ;     return 0;   }   