#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  vector<vector<int> > _o(n + 1);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    _o[a[i]].push_back(i);
  }
  std::mt19937 gen(time(0));
  std::uniform_int_distribution<int> dis;
  using param_type = uniform_int_distribution<int>::param_type;
  for (int i = 0; i < q; ++i) {
    int l, r, k;
    cin >> l >> r >> k;
    l--;
    int ans = 100000000;
    for (int _ = 0; _ < 70; ++_) {
      int val = a[dis(gen, param_type(l, r - 1))];
      const vector<int> &o = _o[val];
      int beg = distance(o.begin(), lower_bound(o.begin(), o.end(), l));
      int end = beg + (r - l) / k;
      if (end < o.size() && o[end] < r && val < ans) ans = val;
    }
    cout << ((ans == 100000000) ? -1 : ans) << "\n";
  }
  return 0;
}
