#include <bits/stdc++.h>
using namespace std;

#define sz(x) static_cast<int>((x).size())

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}
template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res.push_back(static_cast<char>('0' + v[i]));
	}
	return res;
}
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> vec(n);
	for(auto& x: vec) cin >> x;
	set<pair<pii, int>> s;
	for(int i = 0; i < n; ++i) {
		if(i == n - 1) {
			s.insert({{n - 1, n - 1}, vec[n - 1]});
			break;
		}
		int start = i;
		while(i < n - 1 && vec[i] == vec[i + 1]) i++;
		s.insert({{start, i}, vec[start]});
	}
	// debug(s);
	for(int mm = 0; mm < m; ++mm) {
		int l, r, x;
		cin >> l >> r >> x;
		l--;
		r--;
		auto it = prev(s.upper_bound({{l, r}, INT_MAX}));
		// debug(*it);
		auto val = it->first;
		if(val.first <= l && val.second >= r && x == it->second) {
			cout << -1 << '\n';
		} else {
			if(it->second != x) {
				if(vec[l] == x) {
					cout << r + 1 << '\n';
				} else {
					cout << l + 1 << '\n';
				}
			} else if(val.second < r) {
				cout << next(it)->first.second + 1 << '\n';
			} else {
				cout << val.first + 1 << '\n';
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sz(x) static_cast<int>((x).size())

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}
template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res.push_back(static_cast<char>('0' + v[i]));
	}
	return res;
}
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> vec(n);
	for(auto& x: vec) cin >> x;
	set<pair<pii, int>> s;
	for(int i = 0; i < n; ++i) {
		if(i == n - 1) {
			s.insert({{n - 1, n - 1}, vec[n - 1]});
			break;
		}
		int start = i;
		while(i < n - 1 && vec[i] == vec[i + 1]) i++;
		s.insert({{start, i}, vec[start]});
	}
	// debug(s);
	for(int mm = 0; mm < m; ++mm) {
		int l, r, x;
		cin >> l >> r >> x;
		l--;
		r--;
		auto it = prev(s.upper_bound({{l, r}, INT_MAX}));
		// debug(*it);
		auto val = it->first;
		if(val.first <= l && val.second >= r && x == it->second) {
			cout << -1 << '\n';
		} else {
			if(it->second != x) {
				if(vec[l] == x) {
					cout << r + 1 << '\n';
				} else {
					cout << l + 1 << '\n';
				}
			} else if(val.second < r) {
				cout << next(it)->first.second + 1 << '\n';
			} else {
				cout << -1 << '\n';
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sz(x) static_cast<int>((x).size())

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}
template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res.push_back(static_cast<char>('0' + v[i]));
	}
	return res;
}
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> vec(n);
	for(auto& x: vec) cin >> x;
	set<int> s{0};
	for(int i = 1; i < n; ++i) {
		if(vec[i - 1] != vec[i]) s.insert(i);
	}
	int ans;
	int l, r, x;
	auto check = [&](int pass) {
		if(pass >= l && pass <= r && vec[pass] != x) {
			ans = pass;
		}
	};
	for(int mmm = 0; mmm < m; ++mmm) {
		cin >> l >> r >> x;
		ans = -2;
		l--, r--;
		check(l);
		check(r);
		auto it = s.upper_bound(l);
		if(it != s.end()) check(*it);
		cout << ans + 1 << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sz(x) static_cast<int>((x).size())

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}
template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res.push_back(static_cast<char>('0' + v[i]));
	}
	return res;
}
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> vec(n);
	for(auto& x: vec) cin >> x;
	set<pair<pii, int>> s;
	for(int i = 0; i < n; ++i) {
		if(i == n - 1) {
			s.insert({{n - 1, n - 1}, vec[n - 1]});
			break;
		}
		int start = i;
		while(i < n - 1 && vec[i] == vec[i + 1]) i++;
		s.insert({{start, i}, vec[start]});
	}
	// debug(s);
	for(int mm = 0; mm < m; ++mm) {
		int l, r, x;
		cin >> l >> r >> x;
		l--;
		r--;
		auto it = prev(s.upper_bound({{l, r}, INT_MAX}));
		debug(*it);
		auto val = it->first;
		if(val.first <= l && val.second >= r && x == it->second) {
			cout << -1 << '\n';
		} else {
			if(it->second != x) {
				if(vec[l] == x) {
					cout << r + 1 << '\n';
				} else {
					cout << l + 1 << '\n';
				}
			} else if(val.first > l) {
				cout << prev(it)->first.first + 1 << '\n';
			} else if(val.second < r) {
				cout << next(it)->first.first + 1 << '\n';
			} else {
				cout << -1 << '\n';
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sz(x) static_cast<int>((x).size())

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}
template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res.push_back(static_cast<char>('0' + v[i]));
	}
	return res;
}
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> vec(n);
	for(auto& x: vec) cin >> x;
	set<pair<pii, int>> s;
	for(int i = 0; i < n; ++i) {
		if(i == n - 1) {
			s.insert({{n - 1, n - 1}, vec[n - 1]});
			break;
		}
		int start = i;
		while(i < n - 1 && vec[i] == vec[i + 1]) i++;
		s.insert({{start, i}, vec[start]});
	}
	// debug(s);
	for(int mm = 0; mm < m; ++mm) {
		int l, r, x;
		cin >> l >> r >> x;
		l--;
		r--;
		auto it = prev(s.upper_bound({{l, r}, INT_MAX}));
		// debug(*it);
		auto val = it->first;
		if(val.second >= r && x == it->second) {
			cout << -1 << '\n';
		} else {
			if(it->second != x) {
				if(vec[l] == x) {
					cout << r + 1 << '\n';
				} else {
					cout << l + 1 << '\n';
				}
			} else if(val.second < r) {
				cout << next(it)->first.first + 1 << '\n';
			} else {
				cout << -1 << '\n';
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sz(x) static_cast<int>((x).size())

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}
template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res.push_back(static_cast<char>('0' + v[i]));
	}
	return res;
}
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> vec(n);
	for(auto& x: vec) cin >> x;
	set<int> s{0};
	for(int i = 1; i < n; ++i) {
		if(vec[i - 1] != vec[i]) s.insert(i);
	}
	int ans;
	int l, r, x;
	auto check = [&](int pass) {
		if(pass >= l && pass <= r && vec[pass] != x) {
			ans = pass;
		}
	};
	for(int mmm = 0; mmm < m; ++mmm) {
		cin >> l >> r >> x;
		ans = -2;
		l--, r--;
		check(l);
		check(r);
		auto it = s.lower_bound(l + 1);
		if(it != s.end()) check(*it);
		cout << ans + 1 << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sz(x) static_cast<int>((x).size())

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}
template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res.push_back(static_cast<char>('0' + v[i]));
	}
	return res;
}
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> vec(n);
	for(auto& x: vec) cin >> x;
	set<pair<pii, int>> s;
	for(int i = 0; i < n; ++i) {
		if(i == n - 1) {
			s.insert({{n - 1, n - 1}, vec[n - 1]});
			break;
		}
		int start = i;
		while(i < n - 1 && vec[i] == vec[i + 1]) i++;
		s.insert({{start, i}, vec[start]});
	}
	// debug(s);
	for(int mm = 0; mm < m; ++mm) {
		int l, r, x;
		cin >> l >> r >> x;
		l--;
		r--;
		auto it = prev(s.upper_bound({{l, r}, INT_MAX}));
		debug(*it);
		auto val = it->first;
		if(val.first <= l && val.second >= r && x == it->second) {
			cout << -1 << '\n';
		} else {
			if(l > val.first) {
				cout << prev(it)->first.first + 1 << '\n';
			} else if(r > val.second) {
				cout << next(it)->first.first + 1 << '\n';
			} else {
				cout << val.first + 1 << '\n';
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sz(x) static_cast<int>((x).size())

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}
template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res.push_back(static_cast<char>('0' + v[i]));
	}
	return res;
}
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> vec(n);
	for(auto& x: vec) cin >> x;
	set<pair<pii, int>> s;
	for(int i = 0; i < n; ++i) {
		if(i == n - 1) {
			s.insert({{n - 1, n - 1}, vec[n - 1]});
			break;
		}
		int start = i;
		while(i < n - 1 && vec[i] == vec[i + 1]) i++;
		s.insert({{start, i}, vec[start]});
	}
	// debug(s);
	for(int mm = 0; mm < m; ++mm) {
		int l, r, x;
		cin >> l >> r >> x;
		l--;
		r--;
		auto it = prev(s.upper_bound({{l, r}, INT_MAX}));
		// debug(*it);
		auto val = it->first;
		if(val.first <= l && val.second >= r && x == it->second) {
			cout << -1 << '\n';
		} else {
			if(it->second != x) {
				if(vec[l] == x) {
					cout << r + 1 << '\n';
				} else {
					cout << l + 1 << '\n';
				}
			} else if(val.second < r) {
				cout << next(it)->first.second + 1 << '\n';
			} else {
				cout << val.second + 1 << '\n';
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sz(x) static_cast<int>((x).size())

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}
template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res.push_back(static_cast<char>('0' + v[i]));
	}
	return res;
}
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> vec(n);
	for(auto& x: vec) cin >> x;
	set<pair<pii, int>> s;
	for(int i = 0; i < n; ++i) {
		if(i == n - 1) {
			s.insert({{n - 1, n - 1}, vec[n - 1]});
			break;
		}
		int start = i;
		while(i < n - 1 && vec[i] == vec[i + 1]) i++;
		s.insert({{start, i}, vec[start]});
	}
	// debug(s);
	for(int mm = 0; mm < m; ++mm) {
		int l, r, x;
		cin >> l >> r >> x;
		l--;
		r--;
		auto it = prev(s.upper_bound({{l, r}, INT_MAX}));
		// debug(*it);
		auto val = it->first;
		if(val.first <= l && val.second >= r && x == it->second) {
			cout << -1 << '\n';
		} else {
			if(it->second != x) {
				if(vec[l] == x) {
					cout << r + 1 << '\n';
				} else {
					cout << l + 1 << '\n';
				}
			} else if(val.second < r) {
				cout << next(it)->first.first + 1 << '\n';
			} else {
				cout << -1 << '\n';
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sz(x) static_cast<int>((x).size())

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}
template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res.push_back(static_cast<char>('0' + v[i]));
	}
	return res;
}
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> vec(n);
	for(auto& x: vec) cin >> x;
	set<pair<pii, int>> s;
	for(int i = 0; i < n; ++i) {
		if(i == n - 1) {
			s.insert({{n - 1, n - 1}, vec[n - 1]});
			break;
		}
		int start = i;
		while(i < n - 1 && vec[i] == vec[i + 1]) i++;
		s.insert({{start, i}, vec[start]});
	}
	// debug(s);
	for(int mm = 0; mm < m; ++mm) {
		int l, r, x;
		cin >> l >> r >> x;
		l--;
		r--;
		auto it = prev(s.upper_bound({{l, r}, INT_MAX}));
		debug(*it);
		auto val = it->first;
		if(val.first <= l && val.second >= r && x == it->second) {
			cout << -1 << '\n';
		} else {
			if(l < val.first) {
				cout << prev(it)->first.first + 1 << '\n';
			} else if(r > val.second) {
				cout << next(it)->first.first + 1 << '\n';
			} else {
				cout << val.first + 1 << '\n';
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sz(x) static_cast<int>((x).size())

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}
template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res.push_back(static_cast<char>('0' + v[i]));
	}
	return res;
}
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> vec(n);
	for(auto& x: vec) cin >> x;
	set<pair<pii, int>> s;
	for(int i = 0; i < n; ++i) {
		if(i == n - 1) {
			s.insert({{n - 1, n - 1}, vec[n - 1]});
			break;
		}
		int start = i;
		while(i < n - 1 && vec[i] == vec[i + 1]) i++;
		s.insert({{start, i}, vec[start]});
	}
	// debug(s);
	for(int mm = 0; mm < m; ++mm) {
		int l, r, x;
		cin >> l >> r >> x;
		l--;
		r--;
		auto it = prev(s.upper_bound({{l, r}, INT_MAX}));
		debug(*it);
		auto val = it->first;
		if(val.first <= l && val.second >= r && x == it->second) {
			cout << -1 << '\n';
		} else {
			if(it->second != x) {
				cout << l + 1 << '\n';
			}  else if(val.first > l) {
				cout << prev(it)->first.first + 1 << '\n';
			} else if(val.second < r) {
				cout << next(it)->first.first + 1 << '\n';
			} else {
				cout << val.first + 1 << '\n';
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target ("avx2,avx,fma")
typedef long long int ll;
#define int long long int
typedef long double db;
typedef pair <int,int> ii ;
typedef vector < int > vi ;
typedef vector < ii > vii ;
#define rep(i,n)                   for(int i = 0 ; i < n ; i++)
#define repu(i,a,b)                for(int i = a ; i <= b ; i++)
#define repd(i,b,a)                for(int i = b ; i >= a ; i--)
#define pb push_back
#define fi first
#define se second
#define all(p)                p.begin(),p.end()
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Endl endl
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (int)r;}
template <class T>inline void sary(T st, T nd){while(st<nd)cin>>*st++;/*sf("%d", st++);*/}
int mod=1e9+7;
inline ll mul(ll a, ll b){return ((a%mod)*(b%mod))%mod;}
inline ll add(ll a, ll b){return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a, ll b){return ((a%mod)-(b%mod)+mod)%mod;}
inline ll divi(ll a, ll b) { return (500000004*(a%mod))%mod; }
const int N= 3e5+5;

void solve(){
  int n,m; cin>>n>>m;
  vi v(n); sary(all(v));
  map<int,queue<int>> ma1;
  map<int,vi> ma2;
  rep(i,n) ma1[v[i]].push(i+1);
  for(auto p:ma1) {
    queue<int> q=p.se;
    vi pre(n+1); pre[0]=-1;
    repu(i,1,n) {
      if(q.empty() || q.front()!=i) pre[i]=i;
      else {
        pre[i]=pre[i-1]; q.pop();
      }
    }
    ma2[p.fi]=pre;
  }
  while(m--) {
    int l,r,x; cin>>l>>r>>x;
    if(ma2.find(x)==ma2.end()) {
      cout<<l<<Endl; continue;
    }
    vi pre=ma2[x];
    if(pre[r]==-1) cout<<-1;
    else if(pre[l-1]==-1) cout<<pre[r];
    else if(pre[r]==pre[l-1]) cout<<-1;
    else if(pre[r]!=pre[l-1]) cout<<pre[r];
    cout<<Endl;
  }
}

int32_t main() {
  IOS
  int t=1;
  //cin>>t;
  while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target ("avx2,avx,fma")
typedef long long int ll;
//#define int long long int
typedef long double db;
typedef pair <int,int> ii ;
typedef vector < int > vi ;
typedef vector < ii > vii ;
#define rep(i,n)                   for(int i = 0 ; i < n ; i++)
#define repu(i,a,b)                for(int i = a ; i <= b ; i++)
#define repd(i,b,a)                for(int i = b ; i >= a ; i--)
#define pb push_back
#define fi first
#define se second
#define all(p)                p.begin(),p.end()
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Endl endl
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (int)r;}
template <class T>inline void sary(T st, T nd){while(st<nd)cin>>*st++;/*sf("%d", st++);*/}
int mod=1e9+7;
inline ll mul(ll a, ll b){return ((a%mod)*(b%mod))%mod;}
inline ll add(ll a, ll b){return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a, ll b){return ((a%mod)-(b%mod)+mod)%mod;}
inline ll divi(ll a, ll b) { return (500000004*(a%mod))%mod; }
const int N= 3e5+5;

void solve(){
  int n,m; cin>>n>>m;
  vi v(n); sary(all(v));
  map<int,vii> ma;
  rep(i,n) {
    if(ma[v[i]].size()==0) ma[v[i]].pb({i+1,(i==0?-1:i)});
    else {
      vii t=ma[v[i]];
      int l=(t.back().fi==i?t.back().se:i);
      ma[v[i]].pb({i+1,l});
    }
  }

  while(m--) {
    int le,r,x; cin>>le>>r>>x;
    if(ma.find(x)==ma.end()) {
      cout<<le<<Endl; continue;
    }
    vii t=ma[x];
    int l=0, h=t.size()-1, ans=-1;
    while(l<=h) {
      int m=l+(h-l)/2;
      if(t[m].fi>r) h=m-1;
      else l=m+1, ans=m;
    }
    if(ans==-1 || t[ans].fi!=r) cout<<r;
    else if(t[ans].se<le) cout<<-1;
    else cout<<t[ans].se;
    cout<<Endl;
  }
}

int32_t main() {
  IOS
  int t=1;
  //cin>>t;
  while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target ("avx2,avx,fma")
typedef long long int ll;
//#define int long long int
typedef long double db;
typedef pair <int,int> ii ;
typedef vector < int > vi ;
typedef vector < ii > vii ;
#define rep(i,n)                   for(int i = 0 ; i < n ; i++)
#define repu(i,a,b)                for(int i = a ; i <= b ; i++)
#define repd(i,b,a)                for(int i = b ; i >= a ; i--)
#define pb push_back
#define fi first
#define se second
#define all(p)                p.begin(),p.end()
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Endl endl
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (int)r;}
template <class T>inline void sary(T st, T nd){while(st<nd)cin>>*st++;/*sf("%d", st++);*/}
int mod=1e9+7;
inline ll mul(ll a, ll b){return ((a%mod)*(b%mod))%mod;}
inline ll add(ll a, ll b){return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a, ll b){return ((a%mod)-(b%mod)+mod)%mod;}
inline ll divi(ll a, ll b) { return (500000004*(a%mod))%mod; }
const int N= 3e5+5;

void solve(){
  int n,m; cin>>n>>m;
  vi v(n);
  unordered_map<int,vii> ma;
  rep(i,n) {
    int x; cin>>x;
    if(ma[x].size()==0) ma[x].pb({i+1,(i==0?-1:i)});
    else {
      int l=(ma[x].back().fi==i?ma[x].back().se:i);
      ma[x].pb({i+1,l});
    }
  }
  while(m--) {
    int le,r,x; cin>>le>>r>>x;
    if(ma[x].size()==n) {
      cout<<-1<<Endl; continue;
    }
    int l=0, h=ma[x].size()-1, ans=-1;
    while(l<=h) {
      int m=l+(h-l)/2;
      if(ma[x][m].fi>r) h=m-1;
      else l=m+1, ans=m;
    }
    if(ans==-1 || ma[x][ans].fi!=r) cout<<r;
    else if(ma[x][ans].se<le) cout<<-1;
    else cout<<ma[x][ans].se;
    cout<<Endl;
  }
}

int32_t main() {
  IOS
  int t=1;
  //cin>>t;
  while(t--) solve();
  //int x; cin>>x;
  /*int p=1; mod=2047;
  rep(i,179) p=mul(p,x);
  cout<<p;*/
  /*while(x>0) {
    cout<<x%26<<" "; x/=26;
  }*/
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target ("avx2,avx,fma")
typedef long long int ll;
//#define int long long int
typedef long double db;
typedef pair <int,int> ii ;
typedef vector < int > vi ;
typedef vector < ii > vii ;
#define rep(i,n)                   for(int i = 0 ; i < n ; i++)
#define repu(i,a,b)                for(int i = a ; i <= b ; i++)
#define repd(i,b,a)                for(int i = b ; i >= a ; i--)
#define pb push_back
#define fi first
#define se second
#define all(p)                p.begin(),p.end()
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Endl endl
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (int)r;}
template <class T>inline void sary(T st, T nd){while(st<nd)cin>>*st++;/*sf("%d", st++);*/}
int mod=1e9+7;
inline ll mul(ll a, ll b){return ((a%mod)*(b%mod))%mod;}
inline ll add(ll a, ll b){return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a, ll b){return ((a%mod)-(b%mod)+mod)%mod;}
inline ll divi(ll a, ll b) { return (500000004*(a%mod))%mod; }
const int N= 3e5+5;

void solve(){
  int n,m; cin>>n>>m;
  vi v(n); sary(all(v));
  unordered_map<int,vii> ma;
  rep(i,n) {
    if(ma[v[i]].size()==0) ma[v[i]].pb({i+1,(i==0?-1:i)});
    else {
      vii t=ma[v[i]];
      int l=(t.back().fi==i?t.back().se:i);
      ma[v[i]].pb({i+1,l});
    }
  }

  while(m--) {
    int le,r,x; cin>>le>>r>>x;
    if(ma.find(x)==ma.end()) {
      cout<<le<<Endl; continue;
    }
    vii t=ma[x];
    if(t.size()==n) {
      cout<<-1<<Endl; continue;
    }
    int l=0, h=t.size()-1, ans=-1;
    while(l<=h) {
      int m=l+(h-l)/2;
      if(t[m].fi>r) h=m-1;
      else l=m+1, ans=m;
    }
    if(ans==-1 || t[ans].fi!=r) cout<<r;
    else if(t[ans].se<le) cout<<-1;
    else cout<<t[ans].se;
    cout<<Endl;
  }
}

int32_t main() {
  IOS
  int t=1;
  //cin>>t;
  while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target ("avx2,avx,fma")
typedef long long int ll;
//#define int long long int
typedef long double db;
typedef pair <int,int> ii ;
typedef vector < int > vi ;
typedef vector < ii > vii ;
#define rep(i,n)                   for(int i = 0 ; i < n ; i++)
#define repu(i,a,b)                for(int i = a ; i <= b ; i++)
#define repd(i,b,a)                for(int i = b ; i >= a ; i--)
#define pb push_back
#define fi first
#define se second
#define all(p)                p.begin(),p.end()
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Endl endl
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (int)r;}
template <class T>inline void sary(T st, T nd){while(st<nd)cin>>*st++;/*sf("%d", st++);*/}
int mod=1e9+7;
inline ll mul(ll a, ll b){return ((a%mod)*(b%mod))%mod;}
inline ll add(ll a, ll b){return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a, ll b){return ((a%mod)-(b%mod)+mod)%mod;}
inline ll divi(ll a, ll b) { return (500000004*(a%mod))%mod; }
const int N= 3e5+5;

void solve(){
  int n,m; cin>>n>>m;
  vi v(n); sary(all(v));
  unordered_map<int,vii> ma;
  rep(i,n) {
    if(ma[v[i]].size()==0) ma[v[i]].pb({i+1,(i==0?-1:i)});
    else {
      vii t=ma[v[i]];
      int l=(t.back().fi==i?t.back().se:i);
      ma[v[i]].pb({i+1,l});
    }
  }

  while(m--) {
    int le,r,x; cin>>le>>r>>x;
    if(ma.find(x)==ma.end()) {
      cout<<le<<Endl; continue;
    }
    vii t=ma[x];
    int l=0, h=t.size()-1, ans=-1;
    while(l<=h) {
      int m=l+(h-l)/2;
      if(t[m].fi>r) h=m-1;
      else l=m+1, ans=m;
    }
    if(ans==-1 || t[ans].fi!=r) cout<<r;
    else if(t[ans].se<le) cout<<-1;
    else cout<<t[ans].se;
    cout<<Endl;
  }
}

int32_t main() {
  IOS
  int t=1;
  //cin>>t;
  while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target ("avx2,avx,fma")
typedef long long int ll;
//#define int long long int
typedef long double db;
typedef pair <int,int> ii ;
typedef vector < int > vi ;
typedef vector < ii > vii ;
#define rep(i,n)                   for(int i = 0 ; i < n ; i++)
#define repu(i,a,b)                for(int i = a ; i <= b ; i++)
#define repd(i,b,a)                for(int i = b ; i >= a ; i--)
#define pb push_back
#define fi first
#define se second
#define all(p)                p.begin(),p.end()
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Endl endl
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (int)r;}
template <class T>inline void sary(T st, T nd){while(st<nd)cin>>*st++;/*sf("%d", st++);*/}
int mod=1e9+7;
inline ll mul(ll a, ll b){return ((a%mod)*(b%mod))%mod;}
inline ll add(ll a, ll b){return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a, ll b){return ((a%mod)-(b%mod)+mod)%mod;}
inline ll divi(ll a, ll b) { return (500000004*(a%mod))%mod; }
const int N= 3e5+5;

void solve(){
  int n,m; cin>>n>>m;
  vi v(n); sary(all(v));
  map<int,queue<int>> ma1;
  map<int,vi> ma2;
  rep(i,n) ma1[v[i]].push(i+1);
  for(auto p:ma1) {
    queue<int> q=p.se;
    vi pre(n+1); pre[0]=-1;
    repu(i,1,n) {
      if(q.empty() || q.front()!=i) pre[i]=i;
      else {
        pre[i]=pre[i-1]; q.pop();
      }
    }
    ma2[p.fi]=pre;
  }
  while(m--) {
    int l,r,x; cin>>l>>r>>x;
    if(ma2.find(x)==ma2.end()) {
      cout<<l<<Endl; continue;
    }
    vi pre=ma2[x];
    if(pre[r]==-1) cout<<-1;
    else if(pre[l-1]==-1) cout<<pre[r];
    else if(pre[r]==pre[l-1]) cout<<-1;
    else if(pre[r]!=pre[l-1]) cout<<pre[r];
    cout<<Endl;
  }
}

int32_t main() {
  IOS
  int t=1;
  //cin>>t;
  while(t--) solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll k = 1e6+ 6 ;
ll parent [ k ] , arr [ k ];
ll root ( ll x )
{
	if ( x == parent [ x ] ) return x ;
	x = parent [ x ] ;
	return root ( x ) ;
}

void Union ( ll x , ll y )
{
	ll xx = root ( x ) ;
	ll yy = root ( y ) ;
	if ( xx!= yy ) parent [ xx ] = yy  ;
}
int main() {

	ll n , m ;
	cin >> n >> m ;
	for ( ll i = 0 ; i <= n ; i ++ ) parent [ i ] = i ;
	for ( ll i = 1 ; i <= n ; i ++ )cin >> arr [ i ] ;

	for ( ll i = 1 ; i < n ; i ++ )
	{
		if (  arr [ i ] == arr [ i + 1 ] )
			Union ( i , i + 1 ) ;
	}
    //for ( ll i = 1 ; i <= n ; i ++ ) cout << parent [ i ] << " " ;
    //cout << endl ;
	while ( m-- )
	{
		ll l , r , x , ans (-1 );
		cin >> l >> r >> x ;
		ll rootl =root ( l ) ;
		ll rootr =root ( r ) ;
		//cout << rootl << " " << rootr << endl ;
		if ( rootl == rootr )
		{
			if ( arr [ rootl] != x ) ans = l ;
			else ans = -1 ;
		}
		else
		{
			if ( arr [ rootl ] != x ) ans = l ;
			else if ( arr [ rootr] != x ) ans = r ;
			else ans =   rootl + 1 ;
		}
		cout << ans << endl ;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll k = 1e6+ 6 ;
ll parent [ k ] , arr [ k ];
ll root ( ll x )
{
	if ( x == parent [ x ] ) return x ;
	x = parent [ x ] ;
	return root ( x ) ;
}

void Union ( ll x , ll y )
{
	ll xx = root ( x ) ;
	ll yy = root ( y ) ;
	if ( xx!= yy ) parent [ xx ] = yy  ;
}
int main() {

	ll n , m ;
	cin >> n >> m ;
	for ( ll i = 0 ; i <= n ; i ++ ) parent [ i ] = i ;
	for ( ll i = 1 ; i <= n ; i ++ )cin >> arr [ i ] ;

	for ( ll i = 1 ; i < n ; i ++ )
	{
		if (  arr [ i ] == arr [ i + 1 ] )
			Union ( i , i + 1 ) ;
	}

	while ( m-- )
	{
		ll l , r , x , ans (-1 );
		cin >> l >> r >> x ;
		ll rootl =root ( l ) ;
		ll rootr =root ( r ) ;
		//cout << rootl << " " << rootr << endl ;
		if ( rootl == rootr )
		{
			if ( arr [ rootl] != x ) ans = rootl ;
			else ans = -1 ;
		}
		else
		{
			if ( arr [ rootl ] != x ) ans = rootl ;
			else if ( arr [ rootr] != x ) ans = rootr ;
			else ans =   rootl + 1 ;
		}
		cout << ans << endl ;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll k = 1e6+ 6 ;
ll parent [ k ] , arr [ k ];
ll root ( ll x )
{
	if ( x == parent [ x ] ) return x ;
	x = parent [ x ] ;
	return root ( x ) ;
}

void Union ( ll x , ll y )
{
	ll xx = root ( x ) ;
	ll yy = root ( y ) ;
	if ( xx!= yy ) parent [ xx ] = yy  ;
}
int main() {

	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) ;
	//ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll n , m ;
	cin >> n >> m ;
	for ( ll i = 0 ; i <= n ; i ++ ) parent [ i ] = i ;
	for ( ll i = 1 ; i <= n ; i ++ )cin >> arr [ i ] ;

	for ( ll i = 1 ; i < n ; i ++ )
	{
		if (  arr [ i ] == arr [ i + 1 ] )
			Union ( i , i + 1 ) ;
	}
    //for ( ll i = 1 ; i <= n ; i ++ ) cout << parent [ i ] << " " ;
    //cout << endl ;
	while ( m-- )
	{
		ll l , r , x , ans (-1 );
		cin >> l >> r >> x ;
		ll rootl =root ( l ) ;
		ll rootr =root ( r ) ;
		//cout << rootl << " " << rootr << endl ;
		if ( rootl == rootr )
		{
			if ( arr [ rootl] != x ) ans = l ;
			else ans = -1 ;
		}
		else
		{
			if ( arr [ rootl ] != x ) ans = l ;
			else if ( arr [ rootr] != x ) ans = r ;
			else ans =   rootl + 1 ;
		}
		cout << ans << endl ;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
ll binary_search ( vector < ll > v , ll l , ll r  )
{
	if ( v .size () == 0 ) return -1 ;
	ll x = 0 , y = v.size() ;
	while ( x <= y  )
	{

	   ll mid = ( x + y ) / 2 ;
	   if (	v [ mid ]>= l and v [ mid ] <= r ) return v [mid] ;
	   if ( v [ mid ] > r ) y = mid - 1 ;
	   else if ( v [ mid ] < l ) x = mid +  1 ;
	}
	return -1 ;
}
int main() {

	ll n , m , l , r , x , maxi ( INT_MIN) ;
    cin >> n >> m ;
    set < ll > s ;
    ll arr [ n ] ;
    for ( ll i = 0 ; i < n ; i ++ )
    {
    	cin >> arr [ i ] ;
    	if ( arr [ i ] > maxi ) maxi = arr [ i ] ;
    	s.insert ( arr [ i ] ) ;
    }
    vector < ll > v [ 1000001  ] ;
    for ( auto i : s  )
    {
    	for ( ll j = 0 ; j < n ; j ++ )
    		if ( arr [ j ] != i )
    			v [ i ].push_back ( j + 1 ) ;
    }

    while ( m-- )
    {
    	cin >> l >> r >> x ;
    	if ( s.find( x ) == s.end() ) cout << l << endl ;
    	else cout << binary_search ( v [ x ] , l , r  ) << endl ;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll k = 1e6+ 6 ;
ll parent [ k ] , arr [ k ];

ll root(ll x){
    while(x != parent[x]){
        parent[x] = parent[parent[x]];
        x = parent[x];
    }
    return x;
}

void Union ( ll x , ll y )
{
	ll xx = root ( x ) ;
	ll yy = root ( y ) ;
	if ( xx!= yy ) parent [ xx ] = yy  ;
}
int main() {

	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) ;
	//ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll n , m ;
	cin >> n >> m ;
	for ( ll i = 0 ; i <= n ; i ++ ) parent [ i ] = i ;
	for ( ll i = 1 ; i <= n ; i ++ )cin >> arr [ i ] ;

	for ( ll i = 1 ; i < n ; i ++ )
	{
		if (  arr [ i ] == arr [ i + 1 ] )
			Union ( i , i + 1 ) ;
	}
    //for ( ll i = 1 ; i <= n ; i ++ ) cout << parent [ i ] << " " ;
    //cout << endl ;
	while ( m-- )
	{
		ll l , r , x , ans (-1 );
		cin >> l >> r >> x ;
		ll rootl =root ( l ) ;
		ll rootr =root ( r ) ;
		//cout << rootl << " " << rootr << endl ;
		if ( rootl == rootr )
		{
			if ( arr [ rootl] != x ) ans = l ;
			else ans = -1 ;
		}
		else
		{
			if ( arr [ rootl ] != x ) ans = l ;
			else if ( arr [ rootr] != x ) ans = r ;
			else ans =   rootl + 1 ;
		}
		cout << ans << endl ;
	}
	return 0;
}


/**       In the name of Allah, the Gracious, the Merciful.
*               Praise be to Allah, Lord of the Worlds.
*               **************************************
*
*    I have not failed, I have just found 1000 WAYS that won't work.
*                 __________________________________
*                  Author  : Abd El-Twab  M. Fakhry
*                 __________________________________
*/

#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define  print(arr, l, r)    for(int i = (l); i < (r); cout << arr[i++] << " \n"[i == r])
#define  read(arr, l, r)     for(int i = (l); i < (r); cin >> arr[i++])
#define  repr(i, r, l)       for (int i = r; i > l; i--)
#define  rep(i, l, r)        for (int i = l; i < r; i++)
#define  Unique(n)           (n).erase(unique(all(n)), (n).end())
#define  all(a)              a.begin() , a.end()
#define  RT(n)               return cout << (n) << endl, 0;
#define  sz(a)               (int)a.size()
#define  endl                '\n'
#define  D(x)                cout << #x << " = " << (x) << '\n'
#define  F                   first
#define  S                   second
#define  PB                  push_back
#define  EB                  emplace_back
#define  lsb(x)              (x & -x)
#define  get(n)              find_by_order(n)
#define  sqrt(n)             sqrtl(n)
#define  pow(a, b)           powl(a, b)
#define  indexOf(n)          order_of_key(n)
#define  clr(arr, x)         memset(arr, x, sizeof(arr))
#define  isPowerOfTwo(x)     (x && !(x & (x - 1)))

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long            ll;
typedef unsigned long long   ull;

/**---------------------->>  Constants  <<-----------------------**/

const double    Pi    = 2 * acos(0.0),  Euler = 2.71828182845904523536,
                Error = 1e-9,           GoldenR = (1 + sqrtl(5.0)) / 2;

const ll   Magic = 2305843009213693951;
const int  MxsZ  = (int)2e5 + 9,  oo = 0x3f3f3f3f;
const int  ModP2 = (1 << 30) + 7, ModPT7 = (int)1e9 + 7, ModPT = (int)1e9;

/**---------------->>  Functions & Shortcuts  <<-----------------**/

template <class T>
T Gcd(T a, T b) { return b ? Gcd(b, a % b) : a; }

template <class T>
T Lcm(T a, T b) { return a / Gcd(a, b) * 1ll * b; }

template <class T> /** Phi(a * b) = Phi(a) * Phi(b) where a and b Prime Factors and k their power **/
T Phi(T a, T k) { return pow(a, k - 1) * (a - 1); }

template <class T>
using indexed_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;

template <class T>
using matrix = vector < vector <T> >;

template <class T>
using min_heap = priority_queue < T, vector <T>, greater <T> >;

/** Watch **/
template <class T>
string toString(T x) { stringstream sout; sout << x; return sout.str(); }

#ifdef BFS
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dx4[4] = { 0, 0, 1,-1};
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 }, dy4[4] = { 1,-1, 0, 0};
#endif // BFS

/**------------------>>  Fast input / output  <<-----------------**/

void Fast()
{
    cin.sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin.exceptions(cin.failbit);
}

/**----------------->>  input / output Files  <<-----------------**/

void File()
{
    #ifdef FINO
    freopen("new.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif // FINO
}

/**------------------>>  Initialization gap  <<------------------**/

int n, m, l, r, x, a[MxsZ], next_a[MxsZ];

inline void Solve()
{
	cin >> n >> m;
	read(a, 0, n);

	next_a[n - 1] = -1;

	repr(i, n - 2, -1)
		if(a[i] == a[i + 1])
			next_a[i] = next_a[i + 1];
		else
			next_a[i] = i + 2;

	while(m--)
	{
		cin >> l >> r >> x; l--;
		if(a[l] == x && next_a[l] <= r)
		{
			cout << next_a[l] << endl;
			continue;
		}
		else if(a[l] != x)
		{
			cout << l + 1 << endl;
			continue;
		}
		else
			cout << -1 << endl;
	}
}

/**------------------------->>  Main  <<-------------------------**/

int main()
{
    Fast(); File(); Solve();
}


/**       In the name of Allah, the Gracious, the Merciful.
*               Praise be to Allah, Lord of the Worlds.
*               **************************************
*
*    I have not failed, I have just found 1000 WAYS that won't work.
*                 __________________________________
*                  Author  : Abd El-Twab  M. Fakhry
*                 __________________________________
*/

#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define  print(arr, l, r)    for(int i = (l); i < (r); cout << arr[i++] << " \n"[i == r])
#define  read(arr, l, r)     for(int i = (l); i < (r); cin >> arr[i++])
#define  repr(i, r, l)       for (int i = r; i > l; i--)
#define  rep(i, l, r)        for (int i = l; i < r; i++)
#define  Unique(n)           (n).erase(unique(all(n)), (n).end())
#define  all(a)              a.begin() , a.end()
#define  RT(n)               return cout << (n) << endl, 0;
#define  sz(a)               (int)a.size()
#define  endl                '\n'
#define  D(x)                cout << #x << " = " << (x) << '\n'
#define  F                   first
#define  S                   second
#define  PB                  push_back
#define  EB                  emplace_back
#define  lsb(x)              (x & -x)
#define  get(n)              find_by_order(n)
#define  sqrt(n)             sqrtl(n)
#define  pow(a, b)           powl(a, b)
#define  indexOf(n)          order_of_key(n)
#define  clr(arr, x)         memset(arr, x, sizeof(arr))
#define  isPowerOfTwo(x)     (x && !(x & (x - 1)))

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long            ll;
typedef unsigned long long   ull;

/**---------------------->>  Constants  <<-----------------------**/

const double    Pi    = 2 * acos(0.0),  Euler = 2.71828182845904523536,
                Error = 1e-9,           GoldenR = (1 + sqrtl(5.0)) / 2;

const ll   Magic = 2305843009213693951;
const int  MxsZ  = (int)2e5 + 9,  oo = 0x3f3f3f3f;
const int  ModP2 = (1 << 30) + 7, ModPT7 = (int)1e9 + 7, ModPT = (int)1e9;

/**---------------->>  Functions & Shortcuts  <<-----------------**/

template <class T>
T Gcd(T a, T b) { return b ? Gcd(b, a % b) : a; }

template <class T>
T Lcm(T a, T b) { return a / Gcd(a, b) * 1ll * b; }

template <class T> /** Phi(a * b) = Phi(a) * Phi(b) where a and b Prime Factors and k their power **/
T Phi(T a, T k) { return pow(a, k - 1) * (a - 1); }

template <class T>
using indexed_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;

template <class T>
using matrix = vector < vector <T> >;

template <class T>
using min_heap = priority_queue < T, vector <T>, greater <T> >;

/** Watch **/
template <class T>
string toString(T x) { stringstream sout; sout << x; return sout.str(); }

#ifdef BFS
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dx4[4] = { 0, 0, 1,-1};
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 }, dy4[4] = { 1,-1, 0, 0};
#endif // BFS

/**------------------>>  Fast input / output  <<-----------------**/

void Fast()
{
    cin.sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin.exceptions(cin.failbit);
}

/**----------------->>  input / output Files  <<-----------------**/

void File()
{
    #ifdef FINO
    freopen("new.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif
}

/**------------------>>  Initialization gap  <<------------------**/

int n, m, l, r, x, a[MxsZ], nxt[MxsZ];

inline void Solve()
{
	cin >> n >> m;
	read(a, 0, n);

	nxt[n - 1] = -1;
	repr(i, n - 2, -1)
		nxt[i] = a[i] == a[i + 1] ? nxt[i + 1] : i + 2;

	while(m--)
	{
		cin >> l >> r >> x;
		cout << (a[--l] == x && nxt[l] <= r ? nxt[l] : a[l++] != x ? l : -1) << endl;
	}
}

/**------------------------->>  Main  <<-------------------------**/

int main()
{
    Fast(); File(); Solve();
}


/**       In the name of Allah, the Gracious, the Merciful.
*               Praise be to Allah, Lord of the Worlds.
*               **************************************
*
*    I have not failed, I have just found 1000 WAYS that won't work.
*                 __________________________________
*                  Author  : Abd El-Twab  M. Fakhry
*                 __________________________________
*/

#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define  print2d(arr, r, c)  rep(i, 0, r) rep(j, 0, c) cout << arr[i][j] << " \n"[j == c - 1]
#define  print(arr, l, r)    for(int i = (l); i < (r); cout << arr[i++] << " \n"[i == r])
#define  read(arr, l, r)     for(int i = (l); i < (r); cin >> arr[i++])
#define  repr(i, r, l)       for (int i = r; i > l; i--)
#define  rep(i, l, r)        for (int i = l; i < r; i++)
#define  trav(a, x)          for (auto & a : x)
#define  Unique(n)           (n).erase(unique(all(n)), (n).end())
#define  rsz(sz)             resize(sz)
#define  rall(a)             a.rbegin(), a.rend()
#define  ins(x)              insert(x)
#define  all(a)              a.begin() , a.end()
#define  RT(n)               return cout << (n) << endl, 0;
#define  sz(a)               (int)a.size()
#define  endl                '\n'
#define  D(x)                cout << #x << " = " << (x) << '\n'
#define  F                   first
#define  S                   second
#define  PB                  push_back
#define  EB                  emplace_back
#define  lsb(x)              (x & -x)
#define  get(n)              find_by_order(n)
#define  sqrt(n)             sqrtl(n)
#define  pow(a, b)           powl(a, b)
#define  Swap(n, k)          n ^= k, k ^= n, n ^= k;
#define  indexOf(n)          order_of_key(n)
#define  clr(arr, x)         memset(arr, x, sizeof(arr))
#define  isPowerOfTwo(x)     (x && !(x & (x - 1)))
#define  hasBit(mask, x)     (mask & (1ll << (x)))
#define  smlstOnBit(mask)    (__builtin_ctzll((mask) & (-(mask))))
#define  NumberOfDigits(n)   ((int)log10(n) + 1)
#define  trnOnBit(mask, x)   (mask |= (1ll << (x)))
#define  trnOffBit(mask, x)  (mask &= (~(1ll << (x))))

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long            ll;
typedef unsigned int         uint;
typedef unsigned long long   ull;

/**---------------------->>  Constants  <<-----------------------**/

const double    Pi    = 2 * acos(0.0),  Euler = 2.71828182845904523536,
                Error = 1e-9,           GoldenR = (1 + sqrtl(5.0)) / 2;

const ll   Magic = 2305843009213693951;
const int  MxsZ  = (int)2e5 + 9,  oo = 0x3f3f3f3f;
const int  ModP2 = (1 << 30) + 7, ModPT7 = (int)1e9 + 7, ModPT = (int)1e9;

/**---------------->>  Functions & Shortcuts  <<-----------------**/

template <class T>
T Gcd(T a, T b) { return b ? Gcd(b, a % b) : a; }

template <class T>
T Lcm(T a, T b) { return a / Gcd(a, b) * 1ll * b; }

template <class T> /** Phi(a * b) = Phi(a) * Phi(b) where a and b Prime Factors and k their power **/
T Phi(T a, T k) { return pow(a, k - 1) * (a - 1); }

template <class T>
using indexed_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;

template <class T>
using matrix = vector < vector <T> >;

template <class T>
using min_heap = priority_queue < T, vector <T>, greater <T> >;

/** Watch **/
template <class T>
string toString(T x) { stringstream sout; sout << x; return sout.str(); }

#ifdef BFS
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dx4[4] = { 0, 0, 1,-1};
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 }, dy4[4] = { 1,-1, 0, 0};
#endif // BFS

/**------------------>>  TopologicalSort  <<---------------------**/

template <class T>
vector <T> TopologicalSort(T v, vector <T> adj[])
{
	vector <T> inDegree(v, 0);
	rep(i, 0, v) rep(j, 0, sz(adj[i])) ++inDegree[adj[i][j]];

    vector <T> topOrder;
	queue <T> q;
	rep(i, 0, v) if(!inDegree[i]) q.push(i);

	while(!q.empty())
	{
		T front = q.front(); q.pop();
		topOrder.PB(front);
		rep(i, 0, sz(adj[front]))
		{
			--inDegree[adj[front][i]];
			if(!inDegree[adj[front][i]]) q.push(adj[front][i]);
		}
	}
	return topOrder;
}

/**--------------->>  Modular Exponentiation  <<-----------------**/

ll ModExp(ll a, ll b,ll m = ModPT7)
{
	ll x = 1;
	while(b > 0)
	{
		if(b & 1) x = (x * a) % m;
		a = (a * a) % m;
		b >>= 1ll;D(x);
	}
	return x;
}

/**------------->>  Extended Euclidean Algorithm  <<-------------**/

template <class T>
tuple <T, T, T> ExtendedGcd(T a, T b)
{
    if (!b) return {1, 0, a};
    else
    {
        int x, y, g;
        tie(x, y, g) = ExtendedGcd(b, a % b);
        return {y, x - (a / b) * y, g}; /** X, Y, GCD **/
    }
}

/**------------------>>  Alpha ~ Factorial  <<-------------------**/

template <class T>
T Alpha(T n)
{
	if(!n) return 1;
	return sqrtl(2.0 * Pi * n) * powl((n / Euler), n);
}

/**---------------->>  Sieve of Eratosthenes  <<-----------------**/

#ifdef sieve
bitset <(ll)1e9 + 9> isPrime;
void sieve(ll n)
{
     for(ll i = 5; i * i <= n; i += 6)
     {
         if(!isPrime[i] && i % 3 && i % 2)
            for (ll j = (ll)i * i; j <= n; j += i) isPrime.set(j);

         ll nx = i + 2;
         if(!isPrime[nx] && nx % 3 && nx % 2)
            for (ll j = nx * nx; j <= n; j += nx)  isPrime.set(j);
     }
}
#endif // sieve

/**-------------------->>  Prime Factors  <<---------------------**/

template <class T>
vector < pair <T, T> > primeFactorsPair(T n)
{
	vector < pair <T, T> > ans;
	for (int i = 2; (ll)i * i <= n; ++i)
	{
		if (n % i == 0)
		{
			int cnt = 0;
			while (n % i == 0) n /= i, cnt++;
			if (cnt) ans.push_back({i, cnt});
		}
	}
	if (n > 1) ans.push_back({n, 1});
	return ans;
}

/**--->>  Prime Factors Just Factors without their Powers  <<----**/

template <class T>
vector <T> primeFactors(T n)
{
	vector <T> ans;
	for (int i = 2; (ll)i * i <= n; ++i) if (n % i == 0)
	{
        while (n % i == 0) n /= i;
        ans.push_back(i);
	}
	if (n > 1) ans.push_back(n);
	return ans;
}

/**----------------------->>  Divisors  <<-----------------------**/

template <class T>
void factors(vector < pair <T, T> > primeFactors, vector <T> &ans, T cur = 0, T curRes = 1)
{
	if (cur == primeFactors.size()) { ans.push_back(curRes); return; }
	for (int i = 0; i <= primeFactors[cur].second; ++i)
	{
		factors(primeFactors, ans, cur + 1, curRes);
		curRes *= primeFactors[cur].first;
	}
}

/**---------------------->>  zFunction  <<-----------------------**/

vector <ll> zFunction(string s)
{
	ll n = s.size(), L = 0, R = 0;
	vector <ll> z(n);
	for (int i = 1; i < n; ++i)
	{
		if (i > R)
		{
			L = R = i;
			while (R < n && s[R - L] == s[R]) R++;
			z[i] = R - L, R--;
		}
		else
		{
			ll k = i - L;
			if (z[k] < R - i + 1) z[i] = z[k];
			else
			{
				L = i;
				while (R < n && s[R - L] == s[R]) R++;
				z[i] = R - L, R--;
			}
		}
	}
	return z;
}

/**----------------->>  Inclusion Exclusion  <<------------------**/

template <class T>
T Inclusion_Exclusion(vector <T> v, ll a)
{
    ll re = 0;
    for(int i = 0; i < (1ll << sz(v)); i++)
    {
        ll prod = 1, cnt = 0;
        for(int j = 0; j < sz(v); j++) if(i & (1ll << j))
            prod = prod * (ll)v[j], cnt++;

        if(cnt & 1) re -= (a / prod);
        else        re += (a / prod);
    }
    return re;
}

/**-------------------->>  Pattern Match  <<---------------------**/

vector <ll> patterMatch(string text, string pattern)
{
	string key = pattern + '$' + text;
	vector <ll> z = zFunction(key);
	vector <ll> res;
	ll m = sz(pattern);
	for (int i = m + 1; i < sz(key); ++i) if (z[i] == m) res.push_back(i - m - 1);
	return res;
}

/**------------------------>>  Kaden  <<-------------------------**/

template <class T>
vector <T> kaden(vector <T> &arr)
{
	vector <T> kaden(arr.size());
	kaden[0] = arr[0];
	for (int i = 1; i < sz(arr); ++i) kaden[i] = max(arr[i], arr[i] + kaden[i - 1]);
	return kaden;
}

/**-------------------->>  nCr PreProcess  <<--------------------**/

#ifdef nCrPreProcess
int fact[MxsZ], inv[MxsZ];
void nCrPreProcess()
{
	fact[0] = inv[0] = 1;
	for(int i = 1; i < MxsZ; ++i)
	{
		fact[i] = (fact[i-1] * i) % mod;
		inv[i] = powMod(fact[i], mod - 2, mod);
	}
}

ll nCrQuery(ll n, ll r, ll M = ModPT7)
{
	ll res = 1;
	res = (res * 1ll * fact[n]) % M;
	res = (res * 1ll * inv[r]) % M;
	res = (res * 1ll * inv[n-r]) % M;
	return res;
}
#endif // nCrPreProcess

/**---------------->>  Modular Multiplication  <<----------------**/

template <class T>
T MulMod(T a, T b, T m = ModPT7)
{
	T res = 0;
	a = a % m;
	while (b > 0)
	{
		if (b % 2) res = (res + a) % m;
		a = (a * 2) % m;
		b /= 2;
	}
	return res % m;
}

/**------------------>>  Check Primality  <<---------------------**/

bool is_Prime(ll a)
{
    if(a <= 3) return a > 1;
    if(!(a % 2) || !(a % 3)) return 0;
    for(int i = 5; (ll)i * i <= a; i += 6) if(!(a % i) || !(a % (i + 2))) return 0;
    return 1;
}

/**------------------------->>  nCr  <<--------------------------**/

ll nCr(ll n, ll r, ll m = ModPT7)
{
	if (n < r) return 0;
	ll res = 1, rem = 1;
	for (int i = n - r + 1; i <= n; i++) res = (res * i) % m;
	for (int i = 2; i <= r; i++) rem = (rem * i) % m;
	return (res * ModExp(rem, m - 2, m)) % m;
}

/**----------->>  Modular Multiplicative Inverses  <<------------**/

template <class T>
T ModInverse(T a, T m)
{
	a = a % m;
	for (int x = 1; x < m; ++x) if ((a * x) % m == 1) return x;
	return -1;
}

/**---------------->>  Matrix Exponentiation  <<-----------------**/

/** Structure Array **/
struct Matrix
{
    int r, c;
    int a[2][2] = {};
    Matrix(int r, int c)
    {
        this->r = r;
        this->c = c;
    }
};

Matrix MatMul(Matrix a, Matrix b)
{
    Matrix c = Matrix(a.r, b.c);
    rep(i, 0, a.r) rep(j, 0, b.c) rep(k, 0, b.r)
        c.a[i][j] = (c.a[i][j] + (a.a[i][k]* 1ll * b.a[k][j]) % ModPT7) % ModPT7;
    return c;
}

Matrix MatExp(Matrix a, ll p)
{
    if(p <= 1) return a;
    if(p & 1) return MatMul(MatExp(a, p - 1), a);

    Matrix half = MatExp(a, p >> 1ll);
    return MatMul(half, half);
}

/** Vectors **/
template <class T>
matrix <T> MatMul(matrix <T> A, matrix <T> B)
{
	matrix <T> C(sz(A), vector <int> (sz(B[0])));
	for (int i = 0; i < sz(A); ++i)
		for (int j = 0; j < sz(B[0]); ++j)
		{
			C[i][j] = 0;
			for (int k = 0; k < sz(B); ++k)
                C[i][j] = (C[i][j] + ((A[i][k] * 1ll * B[k][j]) % ModPT7)) % ModPT7;
		}
	return C;
}

template <class T>
matrix <T> MatPow(matrix <T> A, int p)
{
	if (p == 1) return A;
	if (p & 1) return MatMul(A, MatPow(A, p - 1));
	else
	{
		matrix <T> C = MatPow(A, p/2);
		return MatMul(C, C);
	}
}

/**------------------>>  Fast input / output  <<-----------------**/

void Fast()
{
    cin.sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin.exceptions(cin.failbit);
}

/**----------------->>  input / output Files  <<-----------------**/

void File()
{
    #ifdef FINO
    freopen("new.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif // FINO
}

/**------------------>>  Initialization gap  <<------------------**/

int n, m, l, r, x, a[MxsZ], next_a[MxsZ];

inline void Solve()
{
	cin >> n >> m;
	read(a, 0, n);

	next_a[n - 1] = -1;

	repr(i, n - 2, -1)
		if(a[i] == a[i + 1])
			next_a[i] = next_a[i + 1];
		else if(next_a[i + 1] == -1)
			next_a[i] = i + 1;
		else
			next_a[i] = next_a[i + 1] - 1;

	while(m--)
	{
		cin >> l >> r >> x; l--, r--;
		if(a[l] == x && next_a[l] <= r)
		{
			cout << next_a[l] << endl;
			continue;
		}
		else if(a[l] != x)
		{
			cout << l + 1 << endl;
			continue;
		}
		else
			cout << -1 << endl;
	}
}

/**------------------------->>  Main  <<-------------------------**/

int main()
{
    Fast(); File(); Solve();
}


/**       In the name of Allah, the Gracious, the Merciful.
*               Praise be to Allah, Lord of the Worlds.
*               **************************************
*
*    I have not failed, I have just found 1000 WAYS that won't work.
*                 __________________________________
*                  Author  : Abd El-Twab  M. Fakhry
*                 __________________________________
*/

#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define  print2d(arr, r, c)  rep(i, 0, r) rep(j, 0, c) cout << arr[i][j] << " \n"[j == c - 1]
#define  print(arr, l, r)    for(int i = (l); i < (r); cout << arr[i++] << " \n"[i == r])
#define  read(arr, l, r)     for(int i = (l); i < (r); cin >> arr[i++])
#define  repr(i, r, l)       for (int i = r; i > l; i--)
#define  rep(i, l, r)        for (int i = l; i < r; i++)
#define  trav(a, x)          for (auto & a : x)
#define  Unique(n)           (n).erase(unique(all(n)), (n).end())
#define  rsz(sz)             resize(sz)
#define  rall(a)             a.rbegin(), a.rend()
#define  ins(x)              insert(x)
#define  all(a)              a.begin() , a.end()
#define  RT(n)               return cout << (n) << endl, 0;
#define  sz(a)               (int)a.size()
#define  endl                '\n'
#define  D(x)                cout << #x << " = " << (x) << '\n'
#define  F                   first
#define  S                   second
#define  PB                  push_back
#define  EB                  emplace_back
#define  lsb(x)              (x & -x)
#define  get(n)              find_by_order(n)
#define  sqrt(n)             sqrtl(n)
#define  pow(a, b)           powl(a, b)
#define  Swap(n, k)          n ^= k, k ^= n, n ^= k;
#define  indexOf(n)          order_of_key(n)
#define  clr(arr, x)         memset(arr, x, sizeof(arr))
#define  isPowerOfTwo(x)     (x && !(x & (x - 1)))
#define  hasBit(mask, x)     (mask & (1ll << (x)))
#define  smlstOnBit(mask)    (__builtin_ctzll((mask) & (-(mask))))
#define  NumberOfDigits(n)   ((int)log10(n) + 1)
#define  trnOnBit(mask, x)   (mask |= (1ll << (x)))
#define  trnOffBit(mask, x)  (mask &= (~(1ll << (x))))

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long            ll;
typedef unsigned int         uint;
typedef unsigned long long   ull;

/**---------------------->>  Constants  <<-----------------------**/

const double    Pi    = 2 * acos(0.0),  Euler = 2.71828182845904523536,
                Error = 1e-9,           GoldenR = (1 + sqrtl(5.0)) / 2;

const ll   Magic = 2305843009213693951;
const int  MxsZ  = (int)2e5 + 9,  oo = 0x3f3f3f3f;
const int  ModP2 = (1 << 30) + 7, ModPT7 = (int)1e9 + 7, ModPT = (int)1e9;

/**---------------->>  Functions & Shortcuts  <<-----------------**/

template <class T>
T Gcd(T a, T b) { return b ? Gcd(b, a % b) : a; }

template <class T>
T Lcm(T a, T b) { return a / Gcd(a, b) * 1ll * b; }

template <class T> /** Phi(a * b) = Phi(a) * Phi(b) where a and b Prime Factors and k their power **/
T Phi(T a, T k) { return pow(a, k - 1) * (a - 1); }

template <class T>
using indexed_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;

template <class T>
using matrix = vector < vector <T> >;

template <class T>
using min_heap = priority_queue < T, vector <T>, greater <T> >;

/** Watch **/
template <class T>
string toString(T x) { stringstream sout; sout << x; return sout.str(); }

#ifdef BFS
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dx4[4] = { 0, 0, 1,-1};
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 }, dy4[4] = { 1,-1, 0, 0};
#endif // BFS

/**------------------>>  TopologicalSort  <<---------------------**/

template <class T>
vector <T> TopologicalSort(T v, vector <T> adj[])
{
	vector <T> inDegree(v, 0);
	rep(i, 0, v) rep(j, 0, sz(adj[i])) ++inDegree[adj[i][j]];

    vector <T> topOrder;
	queue <T> q;
	rep(i, 0, v) if(!inDegree[i]) q.push(i);

	while(!q.empty())
	{
		T front = q.front(); q.pop();
		topOrder.PB(front);
		rep(i, 0, sz(adj[front]))
		{
			--inDegree[adj[front][i]];
			if(!inDegree[adj[front][i]]) q.push(adj[front][i]);
		}
	}
	return topOrder;
}

/**--------------->>  Modular Exponentiation  <<-----------------**/

ll ModExp(ll a, ll b,ll m = ModPT7)
{
	ll x = 1;
	while(b > 0)
	{
		if(b & 1) x = (x * a) % m;
		a = (a * a) % m;
		b >>= 1ll;D(x);
	}
	return x;
}

/**------------->>  Extended Euclidean Algorithm  <<-------------**/

template <class T>
tuple <T, T, T> ExtendedGcd(T a, T b)
{
    if (!b) return {1, 0, a};
    else
    {
        int x, y, g;
        tie(x, y, g) = ExtendedGcd(b, a % b);
        return {y, x - (a / b) * y, g}; /** X, Y, GCD **/
    }
}

/**------------------>>  Alpha ~ Factorial  <<-------------------**/

template <class T>
T Alpha(T n)
{
	if(!n) return 1;
	return sqrtl(2.0 * Pi * n) * powl((n / Euler), n);
}

/**---------------->>  Sieve of Eratosthenes  <<-----------------**/

#ifdef sieve
bitset <(ll)1e9 + 9> isPrime;
void sieve(ll n)
{
     for(ll i = 5; i * i <= n; i += 6)
     {
         if(!isPrime[i] && i % 3 && i % 2)
            for (ll j = (ll)i * i; j <= n; j += i) isPrime.set(j);

         ll nx = i + 2;
         if(!isPrime[nx] && nx % 3 && nx % 2)
            for (ll j = nx * nx; j <= n; j += nx)  isPrime.set(j);
     }
}
#endif // sieve

/**-------------------->>  Prime Factors  <<---------------------**/

template <class T>
vector < pair <T, T> > primeFactorsPair(T n)
{
	vector < pair <T, T> > ans;
	for (int i = 2; (ll)i * i <= n; ++i)
	{
		if (n % i == 0)
		{
			int cnt = 0;
			while (n % i == 0) n /= i, cnt++;
			if (cnt) ans.push_back({i, cnt});
		}
	}
	if (n > 1) ans.push_back({n, 1});
	return ans;
}

/**--->>  Prime Factors Just Factors without their Powers  <<----**/

template <class T>
vector <T> primeFactors(T n)
{
	vector <T> ans;
	for (int i = 2; (ll)i * i <= n; ++i) if (n % i == 0)
	{
        while (n % i == 0) n /= i;
        ans.push_back(i);
	}
	if (n > 1) ans.push_back(n);
	return ans;
}

/**----------------------->>  Divisors  <<-----------------------**/

template <class T>
void factors(vector < pair <T, T> > primeFactors, vector <T> &ans, T cur = 0, T curRes = 1)
{
	if (cur == primeFactors.size()) { ans.push_back(curRes); return; }
	for (int i = 0; i <= primeFactors[cur].second; ++i)
	{
		factors(primeFactors, ans, cur + 1, curRes);
		curRes *= primeFactors[cur].first;
	}
}

/**---------------------->>  zFunction  <<-----------------------**/

vector <ll> zFunction(string s)
{
	ll n = s.size(), L = 0, R = 0;
	vector <ll> z(n);
	for (int i = 1; i < n; ++i)
	{
		if (i > R)
		{
			L = R = i;
			while (R < n && s[R - L] == s[R]) R++;
			z[i] = R - L, R--;
		}
		else
		{
			ll k = i - L;
			if (z[k] < R - i + 1) z[i] = z[k];
			else
			{
				L = i;
				while (R < n && s[R - L] == s[R]) R++;
				z[i] = R - L, R--;
			}
		}
	}
	return z;
}

/**----------------->>  Inclusion Exclusion  <<------------------**/

template <class T>
T Inclusion_Exclusion(vector <T> v, ll a)
{
    ll re = 0;
    for(int i = 0; i < (1ll << sz(v)); i++)
    {
        ll prod = 1, cnt = 0;
        for(int j = 0; j < sz(v); j++) if(i & (1ll << j))
            prod = prod * (ll)v[j], cnt++;

        if(cnt & 1) re -= (a / prod);
        else        re += (a / prod);
    }
    return re;
}

/**-------------------->>  Pattern Match  <<---------------------**/

vector <ll> patterMatch(string text, string pattern)
{
	string key = pattern + '$' + text;
	vector <ll> z = zFunction(key);
	vector <ll> res;
	ll m = sz(pattern);
	for (int i = m + 1; i < sz(key); ++i) if (z[i] == m) res.push_back(i - m - 1);
	return res;
}

/**------------------------>>  Kaden  <<-------------------------**/

template <class T>
vector <T> kaden(vector <T> &arr)
{
	vector <T> kaden(arr.size());
	kaden[0] = arr[0];
	for (int i = 1; i < sz(arr); ++i) kaden[i] = max(arr[i], arr[i] + kaden[i - 1]);
	return kaden;
}

/**-------------------->>  nCr PreProcess  <<--------------------**/

#ifdef nCrPreProcess
int fact[MxsZ], inv[MxsZ];
void nCrPreProcess()
{
	fact[0] = inv[0] = 1;
	for(int i = 1; i < MxsZ; ++i)
	{
		fact[i] = (fact[i-1] * i) % mod;
		inv[i] = powMod(fact[i], mod - 2, mod);
	}
}

ll nCrQuery(ll n, ll r, ll M = ModPT7)
{
	ll res = 1;
	res = (res * 1ll * fact[n]) % M;
	res = (res * 1ll * inv[r]) % M;
	res = (res * 1ll * inv[n-r]) % M;
	return res;
}
#endif // nCrPreProcess

/**---------------->>  Modular Multiplication  <<----------------**/

template <class T>
T MulMod(T a, T b, T m = ModPT7)
{
	T res = 0;
	a = a % m;
	while (b > 0)
	{
		if (b % 2) res = (res + a) % m;
		a = (a * 2) % m;
		b /= 2;
	}
	return res % m;
}

/**------------------>>  Check Primality  <<---------------------**/

bool is_Prime(ll a)
{
    if(a <= 3) return a > 1;
    if(!(a % 2) || !(a % 3)) return 0;
    for(int i = 5; (ll)i * i <= a; i += 6) if(!(a % i) || !(a % (i + 2))) return 0;
    return 1;
}

/**------------------------->>  nCr  <<--------------------------**/

ll nCr(ll n, ll r, ll m = ModPT7)
{
	if (n < r) return 0;
	ll res = 1, rem = 1;
	for (int i = n - r + 1; i <= n; i++) res = (res * i) % m;
	for (int i = 2; i <= r; i++) rem = (rem * i) % m;
	return (res * ModExp(rem, m - 2, m)) % m;
}

/**----------->>  Modular Multiplicative Inverses  <<------------**/

template <class T>
T ModInverse(T a, T m)
{
	a = a % m;
	for (int x = 1; x < m; ++x) if ((a * x) % m == 1) return x;
	return -1;
}

/**---------------->>  Matrix Exponentiation  <<-----------------**/

/** Structure Array **/
struct Matrix
{
    int r, c;
    int a[2][2] = {};
    Matrix(int r, int c)
    {
        this->r = r;
        this->c = c;
    }
};

Matrix MatMul(Matrix a, Matrix b)
{
    Matrix c = Matrix(a.r, b.c);
    rep(i, 0, a.r) rep(j, 0, b.c) rep(k, 0, b.r)
        c.a[i][j] = (c.a[i][j] + (a.a[i][k]* 1ll * b.a[k][j]) % ModPT7) % ModPT7;
    return c;
}

Matrix MatExp(Matrix a, ll p)
{
    if(p <= 1) return a;
    if(p & 1) return MatMul(MatExp(a, p - 1), a);

    Matrix half = MatExp(a, p >> 1ll);
    return MatMul(half, half);
}

/** Vectors **/
template <class T>
matrix <T> MatMul(matrix <T> A, matrix <T> B)
{
	matrix <T> C(sz(A), vector <int> (sz(B[0])));
	for (int i = 0; i < sz(A); ++i)
		for (int j = 0; j < sz(B[0]); ++j)
		{
			C[i][j] = 0;
			for (int k = 0; k < sz(B); ++k)
                C[i][j] = (C[i][j] + ((A[i][k] * 1ll * B[k][j]) % ModPT7)) % ModPT7;
		}
	return C;
}

template <class T>
matrix <T> MatPow(matrix <T> A, int p)
{
	if (p == 1) return A;
	if (p & 1) return MatMul(A, MatPow(A, p - 1));
	else
	{
		matrix <T> C = MatPow(A, p/2);
		return MatMul(C, C);
	}
}

/**------------------>>  Fast input / output  <<-----------------**/

void Fast()
{
    cin.sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin.exceptions(cin.failbit);
}

/**----------------->>  input / output Files  <<-----------------**/

void File()
{
    #ifdef FINO
    freopen("new.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif // FINO
}

/**------------------>>  Initialization gap  <<------------------**/

int n, m, l, r, x, a[MxsZ], next_a[MxsZ];

inline void Solve()
{
	cin >> n >> m;
	read(a, 0, n);

	next_a[n - 1] = -1;
	next_a[n - 2] = n - 1;

	repr(i, n - 3, -1)
		if(a[i] == a[i + 1])
			next_a[i] = next_a[i + 1];
		else
			next_a[i] = next_a[i + 1] - 1;

	while(m--)
	{
		cin >> l >> r >> x; l--, r--;
		if(a[l] == x && next_a[l] <= r)
		{
			cout << next_a[l] << endl;
			continue;
		}
		else if(a[l] != x)
		{
			cout << l + 1 << endl;
			break;
		}
		else
			cout << -1 << endl;
	}
}

/**------------------------->>  Main  <<-------------------------**/

int main()
{
    Fast(); File(); Solve();
}


/**       In the name of Allah, the Gracious, the Merciful.
*               Praise be to Allah, Lord of the Worlds.
*               **************************************
*
*    I have not failed, I have just found 1000 WAYS that won't work.
*                 __________________________________
*                  Author  : Abd El-Twab  M. Fakhry
*                 __________________________________
*/

#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define  print2d(arr, r, c)  rep(i, 0, r) rep(j, 0, c) cout << arr[i][j] << " \n"[j == c - 1]
#define  print(arr, l, r)    for(int i = (l); i < (r); cout << arr[i++] << " \n"[i == r])
#define  read(arr, l, r)     for(int i = (l); i < (r); cin >> arr[i++])
#define  repr(i, r, l)       for (int i = r; i > l; i--)
#define  rep(i, l, r)        for (int i = l; i < r; i++)
#define  trav(a, x)          for (auto & a : x)
#define  Unique(n)           (n).erase(unique(all(n)), (n).end())
#define  rsz(sz)             resize(sz)
#define  rall(a)             a.rbegin(), a.rend()
#define  ins(x)              insert(x)
#define  all(a)              a.begin() , a.end()
#define  RT(n)               return cout << (n) << endl, 0;
#define  sz(a)               (int)a.size()
#define  endl                '\n'
#define  D(x)                cout << #x << " = " << (x) << '\n'
#define  F                   first
#define  S                   second
#define  PB                  push_back
#define  EB                  emplace_back
#define  lsb(x)              (x & -x)
#define  get(n)              find_by_order(n)
#define  sqrt(n)             sqrtl(n)
#define  pow(a, b)           powl(a, b)
#define  Swap(n, k)          n ^= k, k ^= n, n ^= k;
#define  indexOf(n)          order_of_key(n)
#define  clr(arr, x)         memset(arr, x, sizeof(arr))
#define  isPowerOfTwo(x)     (x && !(x & (x - 1)))
#define  hasBit(mask, x)     (mask & (1ll << (x)))
#define  smlstOnBit(mask)    (__builtin_ctzll((mask) & (-(mask))))
#define  NumberOfDigits(n)   ((int)log10(n) + 1)
#define  trnOnBit(mask, x)   (mask |= (1ll << (x)))
#define  trnOffBit(mask, x)  (mask &= (~(1ll << (x))))

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long            ll;
typedef unsigned int         uint;
typedef unsigned long long   ull;

/**---------------------->>  Constants  <<-----------------------**/

const double    Pi    = 2 * acos(0.0),  Euler = 2.71828182845904523536,
                Error = 1e-9,           GoldenR = (1 + sqrtl(5.0)) / 2;

const ll   Magic = 2305843009213693951;
const int  MxsZ  = (int)2e5 + 9,  oo = 0x3f3f3f3f;
const int  ModP2 = (1 << 30) + 7, ModPT7 = (int)1e9 + 7, ModPT = (int)1e9;

/**---------------->>  Functions & Shortcuts  <<-----------------**/

template <class T>
T Gcd(T a, T b) { return b ? Gcd(b, a % b) : a; }

template <class T>
T Lcm(T a, T b) { return a / Gcd(a, b) * 1ll * b; }

template <class T> /** Phi(a * b) = Phi(a) * Phi(b) where a and b Prime Factors and k their power **/
T Phi(T a, T k) { return pow(a, k - 1) * (a - 1); }

template <class T>
using indexed_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;

template <class T>
using matrix = vector < vector <T> >;

template <class T>
using min_heap = priority_queue < T, vector <T>, greater <T> >;

/** Watch **/
template <class T>
string toString(T x) { stringstream sout; sout << x; return sout.str(); }

#ifdef BFS
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dx4[4] = { 0, 0, 1,-1};
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 }, dy4[4] = { 1,-1, 0, 0};
#endif // BFS

/**------------------>>  TopologicalSort  <<---------------------**/

template <class T>
vector <T> TopologicalSort(T v, vector <T> adj[])
{
	vector <T> inDegree(v, 0);
	rep(i, 0, v) rep(j, 0, sz(adj[i])) ++inDegree[adj[i][j]];

    vector <T> topOrder;
	queue <T> q;
	rep(i, 0, v) if(!inDegree[i]) q.push(i);

	while(!q.empty())
	{
		T front = q.front(); q.pop();
		topOrder.PB(front);
		rep(i, 0, sz(adj[front]))
		{
			--inDegree[adj[front][i]];
			if(!inDegree[adj[front][i]]) q.push(adj[front][i]);
		}
	}
	return topOrder;
}

/**--------------->>  Modular Exponentiation  <<-----------------**/

ll ModExp(ll a, ll b,ll m = ModPT7)
{
	ll x = 1;
	while(b > 0)
	{
		if(b & 1) x = (x * a) % m;
		a = (a * a) % m;
		b >>= 1ll;D(x);
	}
	return x;
}

/**------------->>  Extended Euclidean Algorithm  <<-------------**/

template <class T>
tuple <T, T, T> ExtendedGcd(T a, T b)
{
    if (!b) return {1, 0, a};
    else
    {
        int x, y, g;
        tie(x, y, g) = ExtendedGcd(b, a % b);
        return {y, x - (a / b) * y, g}; /** X, Y, GCD **/
    }
}

/**------------------>>  Alpha ~ Factorial  <<-------------------**/

template <class T>
T Alpha(T n)
{
	if(!n) return 1;
	return sqrtl(2.0 * Pi * n) * powl((n / Euler), n);
}

/**---------------->>  Sieve of Eratosthenes  <<-----------------**/

#ifdef sieve
bitset <(ll)1e9 + 9> isPrime;
void sieve(ll n)
{
     for(ll i = 5; i * i <= n; i += 6)
     {
         if(!isPrime[i] && i % 3 && i % 2)
            for (ll j = (ll)i * i; j <= n; j += i) isPrime.set(j);

         ll nx = i + 2;
         if(!isPrime[nx] && nx % 3 && nx % 2)
            for (ll j = nx * nx; j <= n; j += nx)  isPrime.set(j);
     }
}
#endif // sieve

/**-------------------->>  Prime Factors  <<---------------------**/

template <class T>
vector < pair <T, T> > primeFactorsPair(T n)
{
	vector < pair <T, T> > ans;
	for (int i = 2; (ll)i * i <= n; ++i)
	{
		if (n % i == 0)
		{
			int cnt = 0;
			while (n % i == 0) n /= i, cnt++;
			if (cnt) ans.push_back({i, cnt});
		}
	}
	if (n > 1) ans.push_back({n, 1});
	return ans;
}

/**--->>  Prime Factors Just Factors without their Powers  <<----**/

template <class T>
vector <T> primeFactors(T n)
{
	vector <T> ans;
	for (int i = 2; (ll)i * i <= n; ++i) if (n % i == 0)
	{
        while (n % i == 0) n /= i;
        ans.push_back(i);
	}
	if (n > 1) ans.push_back(n);
	return ans;
}

/**----------------------->>  Divisors  <<-----------------------**/

template <class T>
void factors(vector < pair <T, T> > primeFactors, vector <T> &ans, T cur = 0, T curRes = 1)
{
	if (cur == primeFactors.size()) { ans.push_back(curRes); return; }
	for (int i = 0; i <= primeFactors[cur].second; ++i)
	{
		factors(primeFactors, ans, cur + 1, curRes);
		curRes *= primeFactors[cur].first;
	}
}

/**---------------------->>  zFunction  <<-----------------------**/

vector <ll> zFunction(string s)
{
	ll n = s.size(), L = 0, R = 0;
	vector <ll> z(n);
	for (int i = 1; i < n; ++i)
	{
		if (i > R)
		{
			L = R = i;
			while (R < n && s[R - L] == s[R]) R++;
			z[i] = R - L, R--;
		}
		else
		{
			ll k = i - L;
			if (z[k] < R - i + 1) z[i] = z[k];
			else
			{
				L = i;
				while (R < n && s[R - L] == s[R]) R++;
				z[i] = R - L, R--;
			}
		}
	}
	return z;
}

/**----------------->>  Inclusion Exclusion  <<------------------**/

template <class T>
T Inclusion_Exclusion(vector <T> v, ll a)
{
    ll re = 0;
    for(int i = 0; i < (1ll << sz(v)); i++)
    {
        ll prod = 1, cnt = 0;
        for(int j = 0; j < sz(v); j++) if(i & (1ll << j))
            prod = prod * (ll)v[j], cnt++;

        if(cnt & 1) re -= (a / prod);
        else        re += (a / prod);
    }
    return re;
}

/**-------------------->>  Pattern Match  <<---------------------**/

vector <ll> patterMatch(string text, string pattern)
{
	string key = pattern + '$' + text;
	vector <ll> z = zFunction(key);
	vector <ll> res;
	ll m = sz(pattern);
	for (int i = m + 1; i < sz(key); ++i) if (z[i] == m) res.push_back(i - m - 1);
	return res;
}

/**------------------------>>  Kaden  <<-------------------------**/

template <class T>
vector <T> kaden(vector <T> &arr)
{
	vector <T> kaden(arr.size());
	kaden[0] = arr[0];
	for (int i = 1; i < sz(arr); ++i) kaden[i] = max(arr[i], arr[i] + kaden[i - 1]);
	return kaden;
}

/**-------------------->>  nCr PreProcess  <<--------------------**/

#ifdef nCrPreProcess
int fact[MxsZ], inv[MxsZ];
void nCrPreProcess()
{
	fact[0] = inv[0] = 1;
	for(int i = 1; i < MxsZ; ++i)
	{
		fact[i] = (fact[i-1] * i) % mod;
		inv[i] = powMod(fact[i], mod - 2, mod);
	}
}

ll nCrQuery(ll n, ll r, ll M = ModPT7)
{
	ll res = 1;
	res = (res * 1ll * fact[n]) % M;
	res = (res * 1ll * inv[r]) % M;
	res = (res * 1ll * inv[n-r]) % M;
	return res;
}
#endif // nCrPreProcess

/**---------------->>  Modular Multiplication  <<----------------**/

template <class T>
T MulMod(T a, T b, T m = ModPT7)
{
	T res = 0;
	a = a % m;
	while (b > 0)
	{
		if (b % 2) res = (res + a) % m;
		a = (a * 2) % m;
		b /= 2;
	}
	return res % m;
}

/**------------------>>  Check Primality  <<---------------------**/

bool is_Prime(ll a)
{
    if(a <= 3) return a > 1;
    if(!(a % 2) || !(a % 3)) return 0;
    for(int i = 5; (ll)i * i <= a; i += 6) if(!(a % i) || !(a % (i + 2))) return 0;
    return 1;
}

/**------------------------->>  nCr  <<--------------------------**/

ll nCr(ll n, ll r, ll m = ModPT7)
{
	if (n < r) return 0;
	ll res = 1, rem = 1;
	for (int i = n - r + 1; i <= n; i++) res = (res * i) % m;
	for (int i = 2; i <= r; i++) rem = (rem * i) % m;
	return (res * ModExp(rem, m - 2, m)) % m;
}

/**----------->>  Modular Multiplicative Inverses  <<------------**/

template <class T>
T ModInverse(T a, T m)
{
	a = a % m;
	for (int x = 1; x < m; ++x) if ((a * x) % m == 1) return x;
	return -1;
}

/**---------------->>  Matrix Exponentiation  <<-----------------**/

/** Structure Array **/
struct Matrix
{
    int r, c;
    int a[2][2] = {};
    Matrix(int r, int c)
    {
        this->r = r;
        this->c = c;
    }
};

Matrix MatMul(Matrix a, Matrix b)
{
    Matrix c = Matrix(a.r, b.c);
    rep(i, 0, a.r) rep(j, 0, b.c) rep(k, 0, b.r)
        c.a[i][j] = (c.a[i][j] + (a.a[i][k]* 1ll * b.a[k][j]) % ModPT7) % ModPT7;
    return c;
}

Matrix MatExp(Matrix a, ll p)
{
    if(p <= 1) return a;
    if(p & 1) return MatMul(MatExp(a, p - 1), a);

    Matrix half = MatExp(a, p >> 1ll);
    return MatMul(half, half);
}

/** Vectors **/
template <class T>
matrix <T> MatMul(matrix <T> A, matrix <T> B)
{
	matrix <T> C(sz(A), vector <int> (sz(B[0])));
	for (int i = 0; i < sz(A); ++i)
		for (int j = 0; j < sz(B[0]); ++j)
		{
			C[i][j] = 0;
			for (int k = 0; k < sz(B); ++k)
                C[i][j] = (C[i][j] + ((A[i][k] * 1ll * B[k][j]) % ModPT7)) % ModPT7;
		}
	return C;
}

template <class T>
matrix <T> MatPow(matrix <T> A, int p)
{
	if (p == 1) return A;
	if (p & 1) return MatMul(A, MatPow(A, p - 1));
	else
	{
		matrix <T> C = MatPow(A, p/2);
		return MatMul(C, C);
	}
}

/**------------------>>  Fast input / output  <<-----------------**/

void Fast()
{
    cin.sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin.exceptions(cin.failbit);
}

/**----------------->>  input / output Files  <<-----------------**/

void File()
{
    #ifdef FINO
    freopen("new.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif // FINO
}

/**------------------>>  Initialization gap  <<------------------**/

int n, m, l, r, x, a[MxsZ], next_a[MxsZ];

inline void Solve()
{
	cin >> n >> m;
	read(a, 0, n);

	next_a[n - 1] = -1;

	repr(i, n - 2, -1)
		if(a[i] == a[i + 1])
			next_a[i] = next_a[i + 1];
		else
			next_a[i] = i + 2;

	while(m--)
	{
		cin >> l >> r >> x; l--;
		if(a[l] == x && next_a[l] <= r)
		{
			cout << next_a[l] << endl;
			continue;
		}
		else if(a[l] != x)
		{
			cout << l + 1 << endl;
			continue;
		}
		else
			cout << -1 << endl;
	}
}

/**------------------------->>  Main  <<-------------------------**/

int main()
{
    Fast(); File(); Solve();
}