/**       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 bool Read() {
	cin >> n >> m;
    if (!cin) return false;
    rep(i, 0, n) { cin >> a[i]; if(!cin) return false; }
    return true;
}

inline void Solve()
{
	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();

    while(Read()) 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;
			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  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], 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;
		if(a[--l] == x && next_a[l] <= r)
		{
			cout << next_a[l] << endl;
			continue;
		}
		else if(a[l++] != x)
		{
			cout << l << endl;
			continue;
		}
		else
			cout << -1 << endl;
	}
}

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

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


#include<bits/stdc++.h>
using namespace std;
int main()
{int n,m;
    scanf("%d %d" , &n,&m);
    int a[n+1];
    int b[n+1];
    for(int i=1;i<=n;++i)
    {scanf("%d" , &a[i]);}
    for(int i=1;i<=n;++i)
    {int j=i;
        while(j<=n && a[j]==a[i])
        j++;
        for(int k=i;k<j;++k)
        {b[k]=j;}
    j--;
    i=j;
    }
    for(int i=1;i<=m;++i)
    {int l,r,x;
       scanf("%d %d %d" , l,r,x);
        if(x!=a[l] )
        printf("%d\n" , l);
        else
        {if(r<b[l])
            printf("-1\n");
            else
            printf("%d\n" , b[l]);
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int n,m;
    scanf("%d %d" , &n,&m);
    int a[n+1];
    int b[n+1];
    for(int i=1;i<=n;++i)
    {scanf("%d" , &a[i]);}
    for(int i=1;i<=n;++i)
    {int j=i;
        while(j<=n && a[j]==a[i])
        j++;
        for(int k=i;k<j;++k)
        {b[k]=j;}
    j--;
    i=j;
    }
    for(int i=1;i<=m;++i)
    {int l,r,x;
       scanf("%d %d %d" , &l,&r,&x);
        if(x!=a[l] )
        printf("%d\n" , l);
        else
        {if(r<b[l])
            printf("-1\n");
            else
            printf("%d\n" , b[l]);
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int n,m;
    cin >> n>> m;
    int a[n+1];
    int b[n+1];
    for(int i=1;i<=n;++i)
    {cin >> a[i];}
    for(int i=1;i<=n;++i)
    {int j=i;
        while(j<=n && a[j]==a[i])
        j++;
        for(int k=i;k<j;++k)
        {b[k]=j;}
    i=--j;
    }
    for(int i=1;i<=m;++i)
    {int l,r,x;
        cin >> l>> r>>x;
        if(x!=a[l] )
        cout<<a[l]<<"\n";
        else
        {if(r<b[l])
            cout<<"-1\n";
            else
            cout<<a[b[l]]<<"\n";
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int n,m;
    cin >> n>> m;
    int a[n+1];
    int b[n+1];
    for(int i=1;i<=n;++i)
    {scanf("%d" , &a[i]);}
    for(int i=1;i<=n;++i)
    {int j=i;
        while(j<=n && a[j]==a[i])
        j++;
        for(int k=i;k<j;++k)
        {b[k]=j;}
    j--;
    i=j;
    }
    for(int i=1;i<=m;++i)
    {int l,r,x;
        cin >> l>> r>>x;
        if(x!=a[l] )
        printf("%d\n" , l);
        else
        {if(r<b[l])
            cout<<"-1\n";
            else
            printf("%d\n" , b[l]);
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int n,m;
    cin >> n>> m;
    int a[n+1];
    int b[n+1];
    for(int i=1;i<=n;++i)
    {cin >> a[i];}
    for(int i=1;i<=n;++i)
    {int j=i;
        while(j<=n && a[j]==a[i])
        j++;
        for(int k=i;k<j;++k)
        {b[k]=j;}
    i=--j;
    }
    for(int i=1;i<=m;++i)
    {int l,r,x;
        cin >> l>> r>>x;
        if(x!=a[l] )
        cout<<l<<"\n";
        else
        {if(r<b[l])
            cout<<"-1\n";
            else
            cout<<b[l]<<"\n";
        }

    }
}


// Problem : C. Not Equal on a Segment
// Contest : Codeforces - Educational Codeforces Round 7
// URL : https://codeforces.com/problemset/problem/622/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cerr << #x << " = " << x << '\n'
#define debug_arr(a , n) for(int i = 0 ; i < n ; i++)cerr << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vint vector<int>
#define aint(x) (x).begin() , (x).end()
#define inf 1000000000
#define mod 1000000007

const int max_n = 2e5 + 9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
int power(int a , int b)
{
    int prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int n , m;
int a[max_n];

int log_[max_n];
pair<int,int> st_min[max_n][32] , st_max[max_n][32];
void init(){
	log_[1] = 0;
	for(int i = 2 ; i < max_n ; i++){
		log_[i] = log_[i/2] + 1;
	}
}

void create(){
	for(int i = 0 ; i < n ; i++){
		st_min[i][0].ff = st_max[i][0].ff = a[i];
		st_min[i][0].ss = st_max[i][0].ss = i;
	}

	for(int j = 1 ; j < 28 ; j++){
		for(int i = 0 ; i + (1ll << j) <= n ; i++){
			st_min[i][j].ff = min(st_min[i][j-1].ff , st_min[i + (1ll << (j-1))][j-1].ff);
			st_max[i][j].ff = max(st_max[i][j-1].ff , st_max[i + (1ll << (j-1))][j-1].ff);

			if(st_min[i][j].ff == st_min[i][j-1].ff){
				st_min[i][j].ss = st_min[i][j-1].ss;
			}
			else{
				st_min[i][j].ss = st_min[i + (1ll << (j-1))][j-1].ss;
			}
			if(st_max[i][j].ff == st_max[i][j-1].ff){
				st_max[i][j].ss = st_max[i][j-1].ss;
			}
			else{
				st_max[i][j].ss = st_max[i + (1ll << (j-1))][j-1].ss;
			}
		}
	}
}

pair<int,int> query(int l , int r){
	int k = log_[r - l + 1];

	pair<int,int> p1;

	if(st_min[l][k].ff < st_min[r - (1ll << k) + 1][k].ff){
		p1.ff = st_min[l][k].ss;
	}
	else{
		p1.ff = st_min[r - (1ll << k) + 1][k].ss;
	}
	if(st_max[l][k].ff > st_max[r - (1ll << k) + 1][k].ff){
		p1.ss = st_max[l][k].ss;
	}
	else{
		p1.ss = st_max[r - (1ll << k) + 1][k].ss;
	}

	return p1;
}
int main()
{
		cin >> n >> m;
		for(int i = 0 ; i < n ; i++){
			cin >> a[i];
		}

		init();
		create();

		// for(int i = 0 ; i < n ; i++){
			// for(int j = i ; j < n ; j++){
				// cerr << "(" << i << ", " << j << ") : (" << query(i , j).ff << " : " << query(i , j).ss << ")\n";
			// }
		// }

		while(m--){
			int l , r ,x;
			cin >> l >> r >> x;
			l-- , r--;

			pair<int,int> p1 = query(l , r);
			if(a[p1.ff] == a[p1.ss] && a[p1.ff] == x){
				cout << -1 << "\n";
			}
			else{
				if(a[p1.ff] != x){
					cout << p1.ff + 1 << "\n";
				}
				else cout << p1.ss + 1 << "\n";
			}
		}
    return 0;
}


// Problem : C. Not Equal on a Segment
// Contest : Codeforces - Educational Codeforces Round 7
// URL : https://codeforces.com/problemset/problem/622/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cerr << #x << " = " << x << '\n'
#define debug_arr(a , n) for(int i = 0 ; i < n ; i++)cerr << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vint vector<int>
#define aint(x) (x).begin() , (x).end()
#define inf 1000000000
#define mod 1000000007

const int max_n = 2e5 + 9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
int power(int a , int b)
{
    int prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int n , m;
int a[max_n];

int log_[max_n];
pair<int,int> st_min[max_n][32] , st_max[max_n][32];
void init(){
	log_[1] = 0;
	for(int i = 2 ; i < max_n ; i++){
		log_[i] = log_[i/2] + 1;
	}
}

void create(){
	for(int i = 0 ; i < n ; i++){
		st_min[i][0].ff = st_max[i][0].ff = a[i];
		st_min[i][0].ss = st_max[i][0].ss = i;
	}

	for(int j = 1 ; j < 28 ; j++){
		for(int i = 0 ; i + (1ll << j) <= n ; i++){
			st_min[i][j].ff = min(st_min[i][j-1].ff , st_min[i + (1ll << (j-1))][j-1].ff);
			st_max[i][j].ff = max(st_max[i][j-1].ff , st_max[i + (1ll << (j-1))][j-1].ff);

			if(st_min[i][j].ff == st_min[i][j-1].ff){
				st_min[i][j].ss = st_min[i][j-1].ss;
			}
			else{
				st_min[i][j].ss = st_min[i + (1ll << (j-1))][j-1].ss;
			}
			if(st_max[i][j].ff == st_max[i][j-1].ff){
				st_max[i][j].ss = st_max[i][j-1].ss;
			}
			else{
				st_max[i][j].ss = st_max[i + (1ll << (j-1))][j-1].ss;
			}
		}
	}
}

pair<int,int> query(int l , int r){
	int k = log_[r - l + 1];

	pair<int,int> p1;

	if(st_min[l][k].ff < st_min[r - (1ll << k) + 1][k].ff){
		p1.ff = st_min[l][k].ss;
	}
	else{
		p1.ff = st_min[r - (1ll << k) + 1][k].ss;
	}
	if(st_max[l][k].ff > st_max[r - (1ll << k) + 1][k].ff){
		p1.ss = st_max[l][k].ss;
	}
	else{
		p1.ss = st_max[r - (1ll << k) + 1][k].ss;
	}

	return p1;
}
int main()
{
		scanf("%d%d" , &n , &m);
		for(int i = 0 ; i < n ; i++){
			scanf("%d" , &a[i]);
		}

		init();
		create();

		// for(int i = 0 ; i < n ; i++){
			// for(int j = i ; j < n ; j++){
				// cerr << "(" << i << ", " << j << ") : (" << query(i , j).ff << " : " << query(i , j).ss << ")\n";
			// }
		// }

		while(m--){
			int l , r ,x;
			scanf("%d%d%d" , &l , &r , &x);
			l-- , r--;

			pair<int,int> p1 = query(l , r);
			if(a[p1.ff] == a[p1.ss] && a[p1.ff] == x){
				puts("-1");
			}
			else{
				if(a[p1.ff] != x){
					printf("%d\n" , p1.ff + 1);
				}
				else printf("%d\n" , p1.ss + 1);
			}
		}
    return 0;
}


// Problem : C. Not Equal on a Segment
// Contest : Codeforces - Educational Codeforces Round 7
// URL : https://codeforces.com/problemset/problem/622/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cerr << #x << " = " << x << '\n'
#define debug_arr(a , n) for(int i = 0 ; i < n ; i++)cerr << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vint vector<int>
#define aint(x) (x).begin() , (x).end()
#define inf 1000000000
#define mod 1000000007

const int max_n = 2e5 + 9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
int power(int a , int b)
{
    int prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int n , m;
int a[max_n];

int log_[max_n];
pair<int,int> st_min[max_n][32] , st_max[max_n][32];
void init(){
	log_[1] = 0;
	for(int i = 2 ; i < max_n ; i++){
		log_[i] = log_[i/2] + 1;
	}
}

void create(){
	for(int i = 0 ; i < n ; i++){
		st_min[i][0].ff = st_max[i][0].ff = a[i];
		st_min[i][0].ss = st_max[i][0].ss = i;
	}

	for(int j = 1 ; j < 32 ; j++){
		for(int i = 0 ; i + (1ll << j) <= n ; i++){
			st_min[i][j].ff = min(st_min[i][j-1].ff , st_min[i + (1ll << (j-1))][j-1].ff);
			st_max[i][j].ff = max(st_max[i][j-1].ff , st_max[i + (1ll << (j-1))][j-1].ff);

			if(st_min[i][j].ff == st_min[i][j-1].ff){
				st_min[i][j].ss = st_min[i][j-1].ss;
			}
			else{
				st_min[i][j].ss = st_min[i + (1ll << (j-1))][j-1].ss;
			}
			if(st_max[i][j].ff == st_max[i][j-1].ff){
				st_max[i][j].ss = st_max[i][j-1].ss;
			}
			else{
				st_max[i][j].ss = st_max[i + (1ll << (j-1))][j-1].ss;
			}
		}
	}
}

pair<int,int> query(int l , int r){
	int k = log_[r - l + 1];

	pair<int,int> p1;

	if(st_min[l][k].ff < st_min[r - (1ll << k) + 1][k].ff){
		p1.ff = st_min[l][k].ss;
	}
	else{
		p1.ff = st_min[r - (1ll << k) + 1][k].ss;
	}
	if(st_max[l][k].ff > st_max[r - (1ll << k) + 1][k].ff){
		p1.ss = st_max[l][k].ss;
	}
	else{
		p1.ss = st_max[r - (1ll << k) + 1][k].ss;
	}

	return p1;
}
int main()
{
		cin >> n >> m;
		for(int i = 0 ; i < n ; i++){
			cin >> a[i];
		}

		init();
		create();

		// for(int i = 0 ; i < n ; i++){
			// for(int j = i ; j < n ; j++){
				// cerr << "(" << i << ", " << j << ") : (" << query(i , j).ff << " : " << query(i , j).ss << ")\n";
			// }
		// }

		while(m--){
			int l , r ,x;
			cin >> l >> r >> x;
			l-- , r--;

			pair<int,int> p1 = query(l , r);
			if(a[p1.ff] == a[p1.ss] && a[p1.ff] == x){
				cout << -1 << "\n";
			}
			else{
				if(a[p1.ff] != x){
					cout << p1.ff + 1 << "\n";
				}
				else cout << p1.ss + 1 << "\n";
			}
		}
    return 0;
}


// Problem : C. Not Equal on a Segment
// Contest : Codeforces - Educational Codeforces Round 7
// URL : https://codeforces.com/problemset/problem/622/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cerr << #x << " = " << x << '\n'
#define debug_arr(a , n) for(ll i = 0 ; i < n ; i++)cerr << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll>
#define all(x) (x).begin() , (x).end()
#define inf 1000000000
#define mod 1000000007

const ll max_n = 2e5 + 9;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
ll n , m;
ll a[max_n];

ll log_[max_n];
pair<ll,ll> st_min[max_n][32] , st_max[max_n][32];
void init(){
	log_[1] = 0;
	for(ll i = 2 ; i < max_n ; i++){
		log_[i] = log_[i/2] + 1;
	}
}

void create(){
	for(ll i = 0 ; i < n ; i++){
		st_min[i][0].ff = st_max[i][0].ff = a[i];
		st_min[i][0].ss = st_max[i][0].ss = i;
	}

	for(ll j = 1 ; j < 32 ; j++){
		for(ll i = 0 ; i + (1ll << j) <= n ; i++){
			st_min[i][j].ff = min(st_min[i][j-1].ff , st_min[i + (1ll << (j-1))][j-1].ff);
			st_max[i][j].ff = max(st_max[i][j-1].ff , st_max[i + (1ll << (j-1))][j-1].ff);

			if(st_min[i][j].ff == st_min[i][j-1].ff){
				st_min[i][j].ss = st_min[i][j-1].ss;
			}
			else{
				st_min[i][j].ss = st_min[i + (1ll << (j-1))][j-1].ss;
			}
			if(st_max[i][j].ff == st_max[i][j-1].ff){
				st_max[i][j].ss = st_max[i][j-1].ss;
			}
			else{
				st_max[i][j].ss = st_max[i + (1ll << (j-1))][j-1].ss;
			}
		}
	}
}

pair<ll,ll> query(ll l , ll r){
	ll k = log_[r - l + 1];

	pair<ll,ll> p1;

	if(st_min[l][k].ff < st_min[r - (1 << k) + 1][k].ff){
		p1.ff = st_min[l][k].ss;
	}
	else{
		p1.ff = st_min[r - (1ll << k) + 1][k].ss;
	}
	if(st_max[l][k].ff > st_max[r - (1 << k) + 1][k].ff){
		p1.ss = st_max[l][k].ss;
	}
	else{
		p1.ss = st_max[r - (1ll << k) + 1][k].ss;
	}

	return p1;
}
int main()
{
		cin >> n >> m;
		for(ll i = 0 ; i < n ; i++){
			cin >> a[i];
		}

		init();
		create();

		// for(int i = 0 ; i < n ; i++){
			// for(int j = i ; j < n ; j++){
				// cerr << "(" << i << ", " << j << ") : (" << query(i , j).ff << " : " << query(i , j).ss << ")\n";
			// }
		// }

		while(m--){
			ll l , r ,x;
			cin >> l >> r >> x;
			l-- , r--;

			pair<ll,ll> p1 = query(l , r);
			if(a[p1.ff] == a[p1.ss] && a[p1.ff] == x){
				cout << -1 << "\n";
			}
			else{
				if(a[p1.ff] != x){
					cout << p1.ff + 1 << "\n";
				}
				else cout << p1.ss + 1 << "\n";
			}
		}
    return 0;
}


// Problem : C. Not Equal on a Segment
// Contest : Codeforces - Educational Codeforces Round 7
// URL : https://codeforces.com/problemset/problem/622/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define str string
#define pb push_back
#define vc vector
#define ci cin
#define co cout
#define mod 1000000007
struct sa
{
	ll mn,mx;
};
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,q;
    cin>>n>>q;
    ll a[n],nxt[n];
  memset(nxt,-1,sizeof(nxt));

   for(int i=0;i<n;i++)
   {
   	cin>>a[i];

   }
   for(int i=n-2;i>=0;i--)
   {
   	if(a[i]!=a[i+1])
   	nxt[i]=i+1;
   	else
   	nxt[i]=nxt[i+1];
   }
   while(q--)
    {
    	ll l,r,x,ans;
    	cin>>l>>r>>x;
    	l--;
    	r--;
    	if(a[l]!=x)
    	ans=l+1;
    	else
    	{ if(nxt[l]==-1)
    	 ans=-1;
    	 else
    	ans=nxt[l]+1;
    	}

    	if(ans>r)
    	ans=-1;
    	cout<<ans<<"\n";

    }
}


// Problem : C. Not Equal on a Segment
// Contest : Codeforces - Educational Codeforces Round 7
// URL : https://codeforces.com/problemset/problem/622/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define str string
#define pb push_back
#define vc vector
#define ci cin
#define co cout
#define mod 1000000007
struct sa
{
	ll mn,mx;
};
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,q;
    cin>>n>>q;
    ll a[n],nxt[n];
  memset(nxt,-1,sizeof(nxt));

   for(int i=0;i<n;i++)
   {
   	cin>>a[i];

   }
   for(int i=n-2;i>=0;i--)
   {
   	if(a[i]!=a[i+1])
   	nxt[i]=i+1;
   	else
   	nxt[i]=nxt[i+1];
   }
   while(q--)
    {
    	ll l,r,x,ans;
    	cin>>l>>r>>x;
    	l--;
    	r--;
    	if(a[l]!=x)
    	ans=l+1;
    	else
    	ans=nxt[l]+1;

    	if(ans>r)
    	ans=-1;
    	cout<<ans<<"\n";

    }
}


// Problem : C. Not Equal on a Segment
// Contest : Codeforces - Educational Codeforces Round 7
// URL : https://codeforces.com/problemset/problem/622/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define str string
#define pb push_back
#define vc vector
#define ci cin
#define co cout
#define mod 1000000007
struct sa
{
	ll mn,mx;
};
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,q;
    cin>>n>>q;
    ll a[n];

    ll nblock=sqrt(n);
    ll bsize=n/nblock;
    sa b[n];

    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	b[i].mn=INT_MAX;
    	b[i].mx=INT_MIN;
    }

    for(int i=0;i<n;i++)
    {
    	b[i/bsize].mx=max(b[i/bsize].mx,a[i]);
    	b[i/bsize].mn=min(b[i/bsize].mn,a[i]);

    }

    while(q--)
    {
    	ll f=0;
    	ll l,r,x;
    	cin>>l>>r>>x;
    	l--;
    	r--;
    	ll idx;
    	for(int i=l;i<=r;i++)
    	{
    		//cout<<i<<"\n";
    	if(i%bsize==0&&i+bsize-1<=r)
    	{
    		if(b[i/bsize].mx!=b[i/bsize].mn)
    		{
    			f=1;
    			idx=i;
    			break;

    		}
    		i+=bsize;
    	}
       else
    	{
    			if(a[i]!=x)
    			{ f=1;
    				idx=i;
    				break;
    			}
    	}

    	}
    	if(f==0)
    	cout<<"-1\n";
    	else
    	{
    		for(int i=idx;i<n;i++)
    		{
    			if(a[i]!=x)
    			{
    				cout<<i+1<<"\n";
    				break;
    			}
    		}
    	}
    }

}


// Problem : C. Not Equal on a Segment
// Contest : Codeforces - Educational Codeforces Round 7
// URL : https://codeforces.com/problemset/problem/622/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define str string
#define pb push_back
#define vc vector
#define ci cin
#define co cout
#define mod 1000000007
struct sa
{
	ll mn,mx;
};
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,q;
    cin>>n>>q;
    ll a[n];

    ll nblock=sqrt(n);
    ll bsize=n/nblock;
    sa b[n];

    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	b[i].mn=INT_MAX;
    	b[i].mx=INT_MIN;
    }

    for(int i=0;i<n;i++)
    {
    	b[i/bsize].mx=max(b[i/bsize].mx,a[i]);
    	b[i/bsize].mn=min(b[i/bsize].mn,a[i]);

    }

    while(q--)
    {
    	ll f=0;
    	ll l,r,x;
    	cin>>l>>r>>x;
    	l--;
    	r--;
    	ll idx;
    	for(int i=l;i<=r;i++)
    	{
    		//cout<<i<<"\n";
    	if(i%bsize==0&&i+bsize-1<=r)
    	{
    		if(b[i/bsize].mx!=b[i/bsize].mn||
    		(b[i/bsize].mn!=x||b[i/bsize].mx!=x))
    		{
    			f=1;
    			idx=i;
    			break;

    		}
    		i+=bsize;
    	}
       else
    	{
    			if(a[i]!=x)
    			{ f=1;
    				idx=i;
    				break;
    			}
    	}

    	}
    	if(f==0)
    	cout<<"-1\n";
    	else
    	{
    		for(int i=idx;i<n;i++)
    		{
    			if(a[i]!=x)
    			{
    				cout<<i+1<<"\n";
    				break;
    			}
    		}
    	}
    }

}


// Problem : C. Not Equal on a Segment
// Contest : Codeforces - Educational Codeforces Round 7
// URL : https://codeforces.com/problemset/problem/622/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define str string
#define pb push_back
#define vc vector
#define ci cin
#define co cout
#define mod 1000000007
struct sa
{
	ll mn,mx;
};
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,q;
    cin>>n>>q;
    ll a[n],nxt[n];
  memset(nxt,-1,sizeof(nxt));

   for(int i=0;i<n;i++)
   {
   	cin>>a[i];

   }
   for(int i=n-2;i>=0;i--)
   {
   	if(a[i]!=a[i+1])
   	nxt[i]=i+1;
   	else
   	nxt[i]=nxt[i+1];
   }
   while(q--)
    {
    	ll l,r,x,ans;
    	cin>>l>>r>>x;
    	l--;

    	if(a[l]!=x)
    	ans=l+1;
    	else
    	{ if(nxt[l]==-1)
    	 ans=-1;
    	 else
    	ans=nxt[l]+1;
    	}

    	if(ans>r)
    	ans=-1;
    	cout<<ans<<"\n";

    }
}


#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")

#include<bits/stdc++.h>

using namespace std;

#define M 200500

struct Mo{
    int l, r, x, id;
} Q[M];

int n, m, block, lef, rig, a[M], cnt[M], ans[M];
set<int> s, t[M];

bool cmp(Mo u, Mo v){
    if (u.l/block != v.l/block) return u.l < v.l;
    return u.r < v.r;
}

void add(int pos){
    if (cnt[a[pos]] == 0) s.insert(a[pos]);
    cnt[a[pos]]++;
    t[a[pos]].insert(pos);
}

void remov(int pos){
    if (cnt[a[pos]] == 1) s.erase(a[pos]);
    cnt[a[pos]]--;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;
    block = sqrt(n);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++){
        cin >> Q[i].l >> Q[i].r >> Q[i].x;
        Q[i].id = i;
    }
    sort(Q + 1, Q + m + 1, cmp);
    lef = rig = 0;
    for (int i = 1; i <= m; i++){
        while (lef < Q[i].l){
            remov(lef);
            lef++;
        }
        while (rig > Q[i].r){
            remov(rig);
            rig--;
        }
        while (lef > Q[i].l){
            lef--;
            add(lef);
        }
        while (rig < Q[i].r){
            rig++;
            add(rig);
        }
        ans[Q[i].id] = -1;
        if (s.size() > 0){
            for (auto val : s){
                if (val == Q[i].x) continue;
                ans[Q[i].id] = *prev(t[val].end());
                break;
            }
        }
    }
    for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")

#include<bits/stdc++.h>

using namespace std;

#define M 20050

struct Mo{
    int l, r, x, id;
} Q[M];

int n, m, block, lef, rig, a[M], cnt[M], ans[M];
set<int> s, t[M];

bool cmp(Mo u, Mo v){
    if (u.l/block != v.l/block) return u.l < v.l;
    return u.r < v.r;
}

void add(int pos){
    if (cnt[a[pos]] == 0) s.insert(a[pos]);
    cnt[a[pos]]++;
    t[a[pos]].insert(pos);
}

void remov(int pos){
    if (cnt[a[pos]] == 1) s.erase(a[pos]);
    cnt[a[pos]]--;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;
    block = sqrt(n);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++){
        cin >> Q[i].l >> Q[i].r >> Q[i].x;
        Q[i].id = i;
    }
    sort(Q + 1, Q + m + 1, cmp);
    lef = rig = 0;
    for (int i = 1; i <= m; i++){
        while (lef < Q[i].l){
            remov(lef);
            lef++;
        }
        while (rig > Q[i].r){
            remov(rig);
            rig--;
        }
        while (lef > Q[i].l){
            lef--;
            add(lef);
        }
        while (rig < Q[i].r){
            rig++;
            add(rig);
        }
        ans[Q[i].id] = -1;
        if (s.size() > 0){
            for (auto val : s){
                if (val == Q[i].x) continue;
                ans[Q[i].id] = *prev(t[val].end());
                break;
            }
        }
    }
    for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")

#include<bits/stdc++.h>

using namespace std;

#define M 2005000

struct Mo{
    int l, r, x, id;
} Q[M];

int n, m, block, lef, rig, a[M], cnt[M], ans[M];
set<int> s, t[M];

bool cmp(Mo u, Mo v){
    if (u.l/block != v.l/block) return u.l < v.l;
    return u.r < v.r;
}

void add(int pos){
    if (cnt[a[pos]] == 0) s.insert(a[pos]);
    cnt[a[pos]]++;
    t[a[pos]].insert(pos);
}

void remov(int pos){
    if (cnt[a[pos]] == 1) s.erase(a[pos]);
    cnt[a[pos]]--;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;
    block = sqrt(n);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++){
        cin >> Q[i].l >> Q[i].r >> Q[i].x;
        Q[i].id = i;
    }
    sort(Q + 1, Q + m + 1, cmp);
    lef = rig = 0;
    for (int i = 1; i <= m; i++){
        while (lef < Q[i].l){
            remov(lef);
            lef++;
        }
        while (rig > Q[i].r){
            remov(rig);
            rig--;
        }
        while (lef > Q[i].l){
            lef--;
            add(lef);
        }
        while (rig < Q[i].r){
            rig++;
            add(rig);
        }
        ans[Q[i].id] = -1;
        if (s.size() > 0){
            for (auto val : s){
                if (val == Q[i].x) continue;
                ans[Q[i].id] = *prev(t[val].end());
                break;
            }
        }
    }
    for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
    return 0;
}


/*#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")*/

#include<bits/stdc++.h>

using namespace std;

#define M 20050

struct Mo{
    int l, r, x, id;
} Q[M];

int n, m, block, lef, rig, a[M], cnt[M], ans[M];
set<int> s, t[M];

bool cmp(Mo u, Mo v){
    return u.l < v.l;
    return u.r < v.r;
}

void add(int pos){
    if (cnt[a[pos]] == 0) s.insert(a[pos]);
    cnt[a[pos]]++;
    t[a[pos]].insert(pos);
}

void remov(int pos){
    if (cnt[a[pos]] == 1) s.erase(a[pos]);
    cnt[a[pos]]--;
    t[a[pos]].erase(pos);
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;
    block = sqrt(n);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++){
        cin >> Q[i].l >> Q[i].r >> Q[i].x;
        Q[i].id = i;
    }
    sort(Q + 1, Q + m + 1, cmp);
    lef = rig = 0;
    for (int i = 1; i <= m; i++){
        while (lef < Q[i].l){
            remov(lef);
            lef++;
        }
        while (rig > Q[i].r){
            remov(rig);
            rig--;
        }
        while (lef > Q[i].l){
            lef--;
            add(lef);
        }
        while (rig < Q[i].r){
            rig++;
            add(rig);
        }
        ans[Q[i].id] = -1;
        if (s.size() > 0){
            for (auto val : s){
                if (val == Q[i].x) continue;
                ans[Q[i].id] = *prev(t[val].end());
                break;
            }
        }
    }
    for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")

#include<bits/stdc++.h>

using namespace std;

#define M 1005000

struct Mo{
    int l, r, x, id;
} Q[M];

int n, m, block, lef, rig, a[M], cnt[M], ans[M], t[M], pos[M], nextt[M], pre[M];
set<int> s;

bool cmp(Mo u, Mo v){
    if (u.l/block != v.l/block) return u.l < v.l;
    return u.r < v.r;
}

void add(int pos){
    if (cnt[a[pos]] == 0) s.insert(a[pos]);
    cnt[a[pos]]++;
    t[a[pos]] = pos;
}

void removt(int pos){
    cnt[a[pos]]--;
    if (cnt[a[pos]] == 0){
        s.erase(a[pos]);
        t[a[pos]] = 0;
    }
    else t[a[pos]] = pre[pos];
}

void removs(int pos){
    cnt[a[pos]]--;
    if (cnt[a[pos]] == 0){
        s.erase(a[pos]);
        t[a[pos]] = 0;
    }
    else t[a[pos]] = nextt[pos];
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;
    block = sqrt(n);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++){
        if (pos[a[i]] != 0){
            nextt[pos[a[i]]] = i;
            pre[i] = pos[a[i]];
        }
        pos[a[i]] = i;
    }
    for (int i = 1; i <= m; i++){
        cin >> Q[i].l >> Q[i].r >> Q[i].x;
        Q[i].id = i;
    }
    sort(Q + 1, Q + m + 1, cmp);
    lef = rig = 0;
    for (int i = 1; i <= m; i++){
        while (lef < Q[i].l){
            removs(lef);
            lef++;
        }
        while (rig > Q[i].r){
            removt(rig);
            rig--;
        }
        while (lef > Q[i].l){
            lef--;
            add(lef);
        }
        while (rig < Q[i].r){
            rig++;
            add(rig);
        }
        ans[Q[i].id] = -1;
        if (s.size() > 0){
            for (auto val : s){
                if (val == Q[i].x || t[val] == 0) continue;
                ans[Q[i].id] = t[val];
                break;
            }
        }
    }
    for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")

#include<bits/stdc++.h>

using namespace std;

#define M 1005000

int n, m, L, R, x, a[M], l[M], r[M];
vector<int> v[M];

int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int i = 1; i <= n; i++){
        v[a[i]].push_back(i);
        if (i == 1) l[i] = -1;
        if (i - 1 > 0){
            if (a[i] != a[i - 1]) l[i] = i - 1;
            else l[i] = l[i - 1];
        }
    }

    for (int i = n; i > 0; i--){
        if (i == n) r[i] = -1;
        if (i + 1 <= n){
            if (a[i] != a[i + 1]) r[i] = i + 1;
            else r[i] = r[i + 1];
        }
    }

    for (int i = 1; i <= m; i++){
        cin >> L >> R >> x;
        if (v[x].size() == 0) cout << L << '\n';
        else{
            auto pos = lower_bound(v[x].begin(), v[x].end(), L);
            if (pos == v[x].end()) cout << L << '\n';
            else{
                int lef = l[*pos];
                int rig = r[*pos];
                if (L <= lef && lef <= R) cout << lef << '\n';
                else if (L <= rig && rig <= R) cout << rig << '\n';
                else cout << -1 << '\n';
            }
        }
    }
    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")

#include<bits/stdc++.h>

using namespace std;

#define M 1005000

int n, m, L, R, x, a[M], l[M], r[M];
vector<int> v[M];

int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int i = 1; i <= n; i++){
        v[a[i]].push_back(i);
        if (i == 1) l[i] = -1;
        if (i - 1 > 0){
            if (a[i] != a[i - 1]) l[i] = i - 1;
            else l[i] = l[i - 1];
        }
    }

    for (int i = n; i > 0; i--){
        if (i == n) r[i] = -1;
        if (i + 1 <= n){
            if (a[i] != a[i + 1]) r[i] = i + 1;
            else r[i] = r[i + 1];
        }
    }

    for (int i = 1; i <= m; i++){
        cin >> L >> R >> x;
        if (a[L] != x || v[x].size() == 0) cout << L << '\n';
        else if (a[R] != x) cout << R << '\n';
        else{
            auto pos = lower_bound(v[x].begin(), v[x].end(), L);
            if (pos == v[x].end()) cout << L << '\n';
            else{
                int lef = l[*pos];
                int rig = r[*pos];
                if (L <= lef && lef <= R) cout << lef << '\n';
                else if (L <= rig && rig <= R) cout << rig << '\n';
                else cout << -1 << '\n';
            }
        }
    }
    return 0;
}


/*#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")*/

#include<bits/stdc++.h>

using namespace std;

#define M 2005000

struct Mo{
    int l, r, x, id;
} Q[M];

int n, m, block, lef, rig, a[M], cnt[M], ans[M];
set<int> s, t[M];

bool cmp(Mo u, Mo v){
    return u.l < v.l;
    return u.r < v.r;
}

void add(int pos){
    if (cnt[a[pos]] == 0) s.insert(a[pos]);
    cnt[a[pos]]++;
    t[a[pos]].insert(pos);
}

void remov(int pos){
    if (cnt[a[pos]] == 1) s.erase(a[pos]);
    cnt[a[pos]]--;
    t[a[pos]].erase(pos);
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;
    block = sqrt(n);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++){
        cin >> Q[i].l >> Q[i].r >> Q[i].x;
        Q[i].id = i;
    }
    sort(Q + 1, Q + m + 1, cmp);
    lef = rig = 0;
    for (int i = 1; i <= m; i++){
        while (lef < Q[i].l){
            remov(lef);
            lef++;
        }
        while (rig > Q[i].r){
            remov(rig);
            rig--;
        }
        while (lef > Q[i].l){
            lef--;
            add(lef);
        }
        while (rig < Q[i].r){
            rig++;
            add(rig);
        }
        ans[Q[i].id] = -1;
        if (s.size() > 0){
            for (auto val : s){
                if (val == Q[i].x) continue;
                ans[Q[i].id] = *prev(t[val].end());
                break;
            }
        }
    }
    for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
    return 0;
}


//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include<bits/stdc++.h>

using namespace std;

#define M 1005000

int n, m, L, R, x, a[M], l[M], r[M];
vector<int> v[M];

int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int i = 1; i <= n; i++){
        v[a[i]].push_back(i);
        if (i == 1) l[i] = -1;
        if (i - 1 > 0){
            if (a[i] != a[i - 1]) l[i] = i - 1;
            else l[i] = l[i - 1];
        }
    }

    for (int i = n; i > 0; i--){
        if (i == n) r[i] = -1;
        if (i + 1 <= n){
            if (a[i] != a[i + 1]) r[i] = i + 1;
            else r[i] = r[i + 1];
        }
    }

    for (int i = 1; i <= m; i++){
        cin >> L >> R >> x;
        if (a[L] != x || v[x].size() == 0) cout << L << '\n';
        else if (a[R] != x) cout << R << '\n';
        else{
            auto pos = lower_bound(v[x].begin(), v[x].end(), L);
            if (pos == v[x].end()) cout << L << '\n';
            else{
                int lef = l[*pos];
                int rig = r[*pos];
                if (L <= lef && lef <= R) cout << lef << '\n';
                else if (L <= rig && rig <= R) cout << rig << '\n';
                else cout << -1 << '\n';
            }
        }
    }
    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")

#include<bits/stdc++.h>

using namespace std;

#define M 1005000

struct Mo{
    int l, r, x, id;
} Q[M];

int n, m, block, lef, rig, a[M], cnt[M], ans[M];
set<int> s, t[M];

bool cmp(Mo u, Mo v){
    if (u.l/block != v.l/block) return u.l < v.l;
    return u.r < v.r;
}

void add(int pos){
    if (cnt[a[pos]] == 0) s.insert(a[pos]);
    cnt[a[pos]]++;
    t[a[pos]].insert(pos);
}

void remov(int pos){
    if (cnt[a[pos]] == 1) s.erase(a[pos]);
    cnt[a[pos]]--;
    t[a[pos]].erase(pos);
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;
    block = sqrt(n);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++){
        cin >> Q[i].l >> Q[i].r >> Q[i].x;
        Q[i].id = i;
    }
    sort(Q + 1, Q + m + 1, cmp);
    lef = rig = 0;
    for (int i = 1; i <= m; i++){
        while (lef < Q[i].l){
            remov(lef);
            lef++;
        }
        while (rig > Q[i].r){
            remov(rig);
            rig--;
        }
        while (lef > Q[i].l){
            lef--;
            add(lef);
        }
        while (rig < Q[i].r){
            rig++;
            add(rig);
        }
        ans[Q[i].id] = -1;
        if (s.size() > 0){
            for (auto val : s){
                if (val == Q[i].x) continue;
                ans[Q[i].id] = *prev(t[val].end());
                break;
            }
        }
    }
    for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);

    int n,m;cin>>n>>m;
    vector<int> v(n+1);
    int root=sqrt(n);
    vector<vector<pair<int,int>>> de(1000);
    for(int i=1;i<=n;i++){
    	cin>>v[i];
    	de[i/root].push_back({v[i],i});
    }
    for(auto& x:de){
    	sort(x.begin(),x.end());
    }
    while(m--){
    	int l,r,x;cin>>l>>r>>x;
    	bool done=0;
    	set<int> s;
    	for(int i=l;i<=r;i++){
    		if(i%root==0&&r>=i+root-1){
    			if(de[i/root][0].first!=x||de[i/root][de[i/root].size()-1].first!=x){
    				cout<<(de[i/root][0].first!=x?de[i/root][0].second:de[i/root][de[i/root].size()-1].second)<<endl;
    				done=1;
    				break;
    			}
    			i+=(root-1);
    		}
    		else if(v[i]!=x){
    			cout<<i<<endl;
    			done=1;
    			break;
    		}
    	}
    	if(!done){
    		cout<<-1<<endl;
    	}
    }

    #ifndef ONLINE_JUDGE
    	cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);

    int n,m;
    scanf("%d%d",&n,&m);
    vector<int> v(n+1);
    int root=sqrt(n);
    vector<vector<pair<int,int>>> de(1000);
    for(int i=1;i<=n;i++){
    	scanf("%d",&v[i]);
    	de[i/root].push_back({v[i],i});
    }
    for(auto& x:de){
    	sort(x.begin(),x.end());
    }
    int l,r,x;
    pair<int,int> a,b;
    while(m--){
    	scanf("%d%d%d",&l,&r,&x);
    	bool done=0;
    	for(int i=l;i<=r;i++){
    		if(i%root==0&&r>=i+root-1){
    			a=de[i/root][0];
    			b=de[i/root][de[i/root].size()-1];
    			if(a.first!=x||b.first!=x){
    				printf("%d\n",(a.first!=x?a.second:b.second));
    				done=1;
    				break;
    			}
    			i+=(root-1);
    		}
    		else if(v[i]!=x){
    			printf("%d\n",i);
    			done=1;
    			break;
    		}
    	}
    	if(!done){
    		printf("%d\n",-1);
    	}
    }

    #ifndef ONLINE_JUDGE
    	cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);

    int n,m;cin>>n>>m;
    vector<int> v(n+1);
    int root=sqrt(n);
    vector<vector<pair<int,int>>> de(1000);
    for(int i=1;i<=n;i++){
    	cin>>v[i];
    	de[i/root].push_back({v[i],i});
    }
    for(auto& x:de){
    	sort(x.begin(),x.end());
    }
    while(m--){
    	int l,r,x;cin>>l>>r>>x;
    	bool done=0;
    	for(int i=l;i<=r;i++){
    		if(i%root==0&&r>=i+root-1){
    			pair<int,int> a=de[i/root][0];
    			pair<int,int> b=de[i/root][de[i/root].size()-1];
    			if(a.first!=x||b.first!=x){
    				cout<<(a.first!=x?a.second:b.second)<<"\n";
    				done=1;
    				break;
    			}
    			i+=(root-1);
    		}
    		else if(v[i]!=x){
    			cout<<i<<"\n";
    			done=1;
    			break;
    		}
    	}
    	if(!done){
    		cout<<-1<<"\n";
    	}
    }

    #ifndef ONLINE_JUDGE
    	cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);

    int n,m;cin>>n>>m;
    vector<int> v(n+1);
    int root=sqrt(n);
    vector<vector<pair<int,int>>> de(1000);
    for(int i=1;i<=n;i++){
    	cin>>v[i];
    	de[i/root].push_back({v[i],i});
    }
    for(auto& x:de){
    	sort(x.begin(),x.end());
    }
    int l,r,x;
    pair<int,int> a,b;
    while(m--){
    	cin>>l>>r>>x;
    	bool done=0;
    	for(int i=l;i<=r;i++){
    		if(i%root==0&&r>=i+root-1){
    			a=de[i/root][0];
    			b=de[i/root][de[i/root].size()-1];
    			if(a.first!=x||b.first!=x){
    				cout<<(a.first!=x?a.second:b.second)<<endl;
    				done=1;
    				break;
    			}
    			i+=(root-1);
    		}
    		else if(v[i]!=x){
    			cout<<i<<endl;
    			done=1;
    			break;
    		}
    	}
    	if(!done){
    		cout<<-1<<endl;
    	}
    }

    #ifndef ONLINE_JUDGE
    	cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);

    int n,m;cin>>n>>m;
    vector<int> v(n+1);
    int root=sqrt(n);
    vector<vector<pair<int,int>>> de(1000);
    for(int i=1;i<=n;i++){
    	cin>>v[i];
    	de[i/root].push_back({v[i],i});
    }
    for(auto& x:de){
    	sort(x.begin(),x.end());
    }
    while(m--){
    	int l,r,x;cin>>l>>r>>x;
    	bool done=0;
    	for(int i=l;i<=r;i++){
    		if(i%root==0&&r>=i+root-1){
    			pair<int,int> a=de[i/root][0];
    			pair<int,int> b=de[i/root][de[i/root].size()-1];
    			if(a.first!=x||b.first!=x){
    				cout<<(a.first!=x?a.second:b.second)<<endl;
    				done=1;
    				break;
    			}
    			i+=(root-1);
    		}
    		else if(v[i]!=x){
    			cout<<i<<endl;
    			done=1;
    			break;
    		}
    	}
    	if(!done){
    		cout<<-1<<endl;
    	}
    }

    #ifndef ONLINE_JUDGE
    	cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m;
int arr[200003], par[200003];
int main() {
    cin >> n >> m;
    for (int k = 1; k <=n; k++)
        cin>>arr[k];

    par[n] = -1;
    for (int k = n - 1; k >= 1; k--) {
        if (arr[k+1] != arr[k]) par[k] = k+1;
        else par[k] = par[k+1];
    }

    for (int k = 0; k < m; k++) {
        int l,r,x;
        cin>>l>>r>>x;
        bool found = false;
        while (!found && l <= r && l != -1) {
            if (arr[l] != x) {
                cout << l << endl;
                found = true;
            } else {
                l = par[l];
            }
        }
        if (!found) cout << -1 << endl;
    }

return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m;
int arr[200003], par[200003];
int main() {
    cin >> n >> m;
    for (int k = 1; k <=n; k++)
        cin>>arr[k];

    par[n] = -1;
    for (int k = n - 1; k >= 1; k--) {
        if (arr[k+1] != arr[k]) par[k] = k+1;
        else par[k] = par[k+1];
    }

    for (int k = 0; k < m; k++) {
        int l,r,x;
        cin>>l>>r>>x;
        bool found = false;
            if (arr[l] != x) {
                cout << l << endl;
            } else {
                if (par[l] <= r) cout << par[l] << endl;
                else cout << -1 << endl;
            }
    }

return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m;
int arr[200003], par[200003],l,r,x;;
int main() {
    scanf("%d %d", &n, &m);
    for (int k = 1; k <=n; k++) {
        scanf("%d", &arr[k]);
        par[k] = (arr[k] == arr[k-1]) ? par[k-1] : k-1;
    }

    for (int k = 0; k < m; k++) {
        scanf("%d %d %d", &l,&r,&x);
        bool found = false;
            if (arr[l] != x) {
                printf("%d \n", l);
            } else {
                if (par[l] <= r && par[l] != 0) printf("%d \n", l);
                else printf("%d \n", -1);
            }
    }

return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m;
int arr[200003], par[200003];
int main() {
    cin >> n >> m;
    for (int k = 1; k <=n; k++)
        cin>>arr[k];

    par[n] = -1;
    for (int k = n - 1; k >= 1; k--) {
        if (arr[k+1] != arr[k]) par[k] = k+1;
        else par[k] = par[k+1];
    }

    for (int k = 0; k < m; k++) {
        int l,r,x;
        cin>>l>>r>>x;
            if (arr[l] != x) {
                cout << l << " ";
            } else {
                if (par[l] <= r) cout << par[l] << " ";
                else cout << -1 << " ";
            }
    }

return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m;
int arr[200003], par[200003],l,r,x;;
int main() {
    scanf("%d %d", &n, &m);
    for (int k = 1; k <=n; k++) {
        scanf("%d", &arr[k]);
        par[k] = (arr[k] == arr[k-1]) ? par[k-1] : k-1;
    }

    for (int k = 0; k <= n; k++) cout << par[k] << " " << endl;
    for (int k = 0; k < m; k++) {
        scanf("%d %d %d", &l,&r,&x);
        bool found = false;
            if (arr[l] != x) {
                printf("%d \n", l);
            } else {
                if (par[l] <= r && par[l] != 0) printf("%d \n", l);
                else printf("%d \n", -1);
            }
    }

return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m;
int arr[200003], par[200003];
int main() {
    cin >> n >> m;
    for (int k = 1; k <=n; k++)
        cin>>arr[k];

    par[n] = -1;
    for (int k = n - 1; k >= 1; k--) {
        if (arr[k+1] != arr[k]) par[k] = k+1;
        else par[k] = par[k+1];
    }

    for (int k = 0; k < m; k++) {
        int l,r,x;
        cin>>l>>r>>x;
        bool found = false;
            if (arr[l] != x) {
                cout << l << " ";
            } else {
                if (par[l] <= r) cout << par[l] << " ";
                else cout << -1 << " ";
            }
    }

return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m;
int arr[200003], par[200003];
int main() {
    cin >> n >> m;
    for (int k = 1; k <=n; k++)
        cin>>arr[k];

    par[n] = -1;
    for (int k = n - 1; k >= 1; k--) {
        if (arr[k+1] != arr[k]) par[k] = k+1;
        else par[k] = par[k+1];
    }

    for (int k = 0; k < m; k++) {
        int l,r,x;
        cin>>l>>r>>x;
        bool found = false;
        while (!found && l <= r) {
            if (arr[l] != x) {
                cout << l << endl;
                found = true;
            } else {
                l = par[l];
            }
        }
        if (!found) cout << -1 << endl;
    }
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m;
int arr[200003], par[200003];
int main() {
    scanf("%d%d", &n,&m);
    for (int k = 1; k <=n; k++)
        scanf("%d", &arr[k]);

    par[n] = -1;
    for (int k = n - 1; k >= 1; k--) {
        if (arr[k+1] != arr[k]) par[k] = k+1;
        else par[k] = par[k+1];
    }

    for (int k = 0; k < m; k++) {
        int l,r,x;
        scanf("%d%d%d", &l,&r,&x);
            if (arr[l] != x) {
                printf("%d", l);
            } else {
                if (par[l] <= r) printf("%d", par[l]);
                else printf("-1");
            }
    }

return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m;
int arr[200003], par[200003];
int main() {
    cin >> n >> m;
    for (int k = 1; k <=n; k++)
        cin>>arr[k];

    par[n] = -1;
    for (int k = n - 1; k >= 1; k--) {
        if (arr[k+1] != arr[k]) par[k] = k+1;
        else par[k] = par[k+1];
    }

    for (int k = 0; k < m; k++) {
        int l,r,x;
        cin>>l>>r>>x;
        bool found = false;
        while (l <= r) {
            if (arr[l] != x) {
                cout << l << endl;
                found = true;
                break;
            } else {
                l = par[l];
                if (par[l] == -1) break;
            }
        }
        if (!found) cout << -1 << endl;
    }

return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m;
int arr[200003], par[200003];
int main() {
    scanf("%d%d", &n,&m);
    for (int k = 1; k <=n; k++)
        scanf("%d", &arr[k]);

    par[n] = -1;
    for (int k = n - 1; k >= 1; k--) {
        if (arr[k+1] != arr[k]) par[k] = k+1;
        else par[k] = par[k+1];
    }

    for (int k = 0; k < m; k++) {
        int l,r,x;
        scanf("%d%d%d", &l,&r,&x);
            if (arr[l] != x) {
                printf("%d\n", l);
            } else {
                if (par[l] <= r) printf("%d\n", par[l]);
                else printf("-1\n");
            }
    }

return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define N 100010

int n, m;
vector<int> G[N];
int a[N], nx[N];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
    }
    nx[n] = n;
    for (int i = n - 1; i >= 1; --i) {
        if (a[i] != a[i + 1]) {
            nx[i] = i;
        } else {
            nx[i] = nx[i + 1];
        }
    }
    for (int cas = 1, l, r, x; cas <= m; ++cas) {
        scanf("%d %d %d", &l, &r, &x);
        if (a[l] != x) {
            printf("%d\n", l);
        } else {
            if (nx[l] < r) {
                printf("%d\n", nx[l]);
            } else {
                puts("-1");
            }
        }

    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define N 100010

int n, m;
vector<int> G[N];
int a[N], nx[N];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
    }
    nx[n] = n + 1;
    for (int i = n - 1; i >= 1; --i) {
        if (a[i] != a[i + 1]) {
            nx[i] = i;
        } else {
            nx[i] = nx[i + 1];
        }
    }
    for (int cas = 1, l, r, x; cas <= m; ++cas) {
        scanf("%d %d %d", &l, &r, &x);
        if (a[l] != x) {
            printf("%d\n", l);
        } else {
            if (nx[l] < r) {
                printf("%d\n", nx[l]);
            } else {
                puts("-1");
            }
        }

    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define N 100010

int n, m;
vector<int> G[N];
int a[N], nx[N];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
    }
    nx[n] = n + 1;
    for (int i = n - 1; i >= 1; --i) {
        if (a[i] != a[i + 1]) {
            nx[i] = i + 1;
        } else {
            nx[i] = nx[i + 1];
        }
    }
    for (int cas = 1, l, r, x; cas <= m; ++cas) {
        scanf("%d %d %d", &l, &r, &x);
        if (a[l] != x) {
            printf("%d\n", l);
        } else {
            if (nx[l] < r) {
                printf("%d\n", nx[l]);
            } else {
                puts("-1");
            }
        }

    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define N 200010

int n, m;
vector<int> G[N];
int a[N], nx[N];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
    }
    nx[n] = n;
    for (int i = n - 1; i >= 1; --i) {
        if (a[i] != a[i + 1]) {
            nx[i] = i;
        } else {
            nx[i] = nx[i + 1];
        }
    }
    for (int cas = 1, l, r, x; cas <= m; ++cas) {
        scanf("%d %d %d", &l, &r, &x);
        if (a[l] != x) {
            printf("%d\n", l);
        } else {
            if (nx[l] < r) {
                printf("%d\n", nx[l] + 1);
            } else {
                puts("-1");
            }
        }

    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define N 100010

int n, m;
vector<int> G[N];
int a[N], nx[N];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
    }
    nx[n] = n;
    for (int i = n - 1; i >= 1; --i) {
        if (a[i] != a[i + 1]) {
            nx[i] = i;
        } else {
            nx[i] = nx[i + 1];
        }
    }
    for (int cas = 1, l, r, x; cas <= m; ++cas) {
        scanf("%d %d %d", &l, &r, &x);
        if (a[l] != x) {
            printf("%d\n", l);
        } else {
            if (nx[l] < r) {
                printf("%d\n", nx[l] + 1);
            } else {
                puts("-1");
            }
        }

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a);
		}
		a=((a)*(a));
		b>>=1;
	}
	return ans;
}

int dfs(int l,int r,vector<int>& v){
	if(r<l)
		return -1;
	if(binary_search(v.begin(),v.end(),l)==false)
		return l;
	if(binary_search(v.begin(),v.end(),r)==false)
		return r;
	int ind1 = lower_bound(v.begin(),v.end(),l) - v.begin();
	int ind2 = lower_bound(v.begin(),v.end(),r) - v.begin();
	if(ind2 - ind1 == r - l)
		return -1;
	int mid = ((l+r)/2);
	ind1 = dfs(l,mid,v);
	if(ind1!=-1)
		return ind1;
	return dfs(mid + 1,r,v);
}

int main() {
	IOS;
	ll t=1;
	//cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		int a[n];
		map<int,vector<int>> ma;
		for(int i=0;i<n;i++){
			cin>>a[i];
			ma[a[i]].push_back(i + 1);
		}
		while(m--){
			int l,r,x;
			cin>>l>>r>>x;
			if(ma.count(x)==false){
				cout<<l<<endl;
				continue;
			}
			int ans = dfs(l,r,ma[x]);
			printf("%d\n", ans);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a);
		}
		a=((a)*(a));
		b>>=1;
	}
	return ans;
}

int dfs(int l,int r,vector<int>& v){
	if(r<l)
		return -1;
	if(binary_search(v.begin(),v.end(),l)==false)
		return l;
	if(binary_search(v.begin(),v.end(),r)==false)
		return r;
	int ind1 = lower_bound(v.begin(),v.end(),l) - v.begin();
	int ind2 = lower_bound(v.begin(),v.end(),r) - v.begin();
	if(ind2 - ind1 == r - l)
		return -1;
	int mid = ((l+r)/2);
	ind1 = dfs(l+1,mid,v);
	if(ind1!=-1)
		return ind1;
	return dfs(mid + 1,r - 1,v);
}

int main() {
	IOS;
	ll t=1;
	//cin>>t;
	while(t--){
		int n,m;
		scanf("%d %d",&n,&m);
		int a[n];
		vector<int> ma[1000005];
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
			ma[a[i]].push_back(i + 1);
		}
		int l,r,x;
		while(m--){
			scanf("%d %d %d",&l,&r,&x);
			if(ma[x].size()==0){
				printf("%d\n",l);
				continue;
			}
			else{
				printf("%d\n",dfs(l,r,ma[x]));
			}

		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a);
		}
		a=((a)*(a));
		b>>=1;
	}
	return ans;
}

int dfs(int l,int r,vector<int>& v){
	if(r<l)
		return -1;
	if(binary_search(v.begin(),v.end(),l)==false)
		return l;
	if(binary_search(v.begin(),v.end(),r)==false)
		return r;
	int ind1 = lower_bound(v.begin(),v.end(),l) - v.begin();
	int ind2 = lower_bound(v.begin(),v.end(),r) - v.begin();
	if(ind2 - ind1 == r - l)
		return -1;
	int mid = ((l+r)/2);
	ind1 = dfs(l,mid,v);
	if(ind1!=-1)
		return ind1;
	return dfs(mid + 1,r,v);
}

int main() {
	IOS;
	ll t=1;
	//cin>>t;
	while(t--){
		int n,m;
		scanf("%d %d",&n,&m);
		int a[n];
		vector<int> ma[1000005];
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
			ma[a[i]].push_back(i + 1);
		}
		int l,r,x;
		while(m--){
			scanf("%d %d %d",&l,&r,&x);
			if(ma[x].size()==0){
				printf("%d\n",l);
				continue;
			}
			else
			printf("%d\n",dfs(l,r,ma[x]));
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a);
		}
		a=((a)*(a));
		b>>=1;
	}
	return ans;
}

int dfs(int l,int r,vector<int>& v){
	if(r<l)
		return -1;
	if(binary_search(v.begin(),v.end(),l)==false)
		return l;
	if(binary_search(v.begin(),v.end(),r)==false)
		return r;
	int ind1 = lower_bound(v.begin(),v.end(),l) - v.begin();
	int ind2 = lower_bound(v.begin(),v.end(),r) - v.begin();
	if(ind2 - ind1 == r - l)
		return -1;
	int mid = ((l+r)/2);
	ind1 = dfs(l,mid,v);
	if(ind1!=-1)
		return ind1;
	return dfs(mid + 1,r,v);
}

int main() {
	IOS;
	ll t=1;
	//cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		int a[n];
		map<int,vector<int>> ma;
		for(int i=0;i<n;i++){
			cin>>a[i];
			ma[a[i]].push_back(i + 1);
		}
		while(m--){
			int l,r,x;
			cin>>l>>r>>x;
			if(ma.count(x)==false){
				cout<<l<<endl;
				continue;
			}
			cout<<dfs(l,r,ma[x])<<endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a);
		}
		a=((a)*(a));
		b>>=1;
	}
	return ans;
}

int dfs(int l,int r,vector<int>& v){
	if(r<l)
		return -1;
	if(binary_search(v.begin(),v.end(),l)==false)
		return l;
	if(binary_search(v.begin(),v.end(),r)==false)
		return r;
	int ind1 = lower_bound(v.begin(),v.end(),l) - v.begin();
	int ind2 = lower_bound(v.begin(),v.end(),r) - v.begin();
	if(ind2 - ind1 == r - l)
		return -1;
	int mid = ((l+r)/2);
	ind1 = dfs(l,mid,v);
	if(ind1!=-1)
		return ind1;
	return dfs(mid + 1,r,v);
}

int main() {
	IOS;
	ll t=1;
	//cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		int a[n];
		map<int,vector<int>> ma;
		for(int i=0;i<n;i++){
			cin>>a[i];
			ma[a[i]].push_back(i + 1);
		}
		while(m--){
			int l,r,x;
			cin>>l>>r>>x;
			if(ma.count(x)==false){
				cout<<l<<endl;
				continue;
			}
			cout<<""<<dfs(l,r,ma[x])<<endl;
		}
	}
	return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a);
		}
		a=((a)*(a));
		b>>=1;
	}
	return ans;
}

int dfs(int l,int r,vector<int>& v){
	if(r<l)
		return -1;
	int ind1 = lower_bound(v.begin(),v.end(),l) - v.begin();
	if(ind1 == v.size() || v[ind1] != l)
		return l;
	int ind2 = lower_bound(v.begin(),v.end(),r) - v.begin();
	if(ind1 == v.size() || v[ind2] != r)
		return r;
	if(ind2 - ind1 == r - l)
		return -1;
	int mid = ((l+r)/2);
	ind1 = dfs(mid + 1,r - 1,v);
	if(ind1!=-1)
		return ind1;
	return dfs(l+1,mid,v);
}

int main() {
	IOS;
	ll t=1;
	//cin>>t;
	while(t--){
		int n,m;
		scanf("%d %d",&n,&m);
		int a[n];
		vector<int> ma[1000005];
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
			ma[a[i]].push_back(i + 1);
		}
		int l,r,x;
		while(m--){
			scanf("%d %d %d",&l,&r,&x);
			if(ma[x].size()==0){
				printf("%d\n",l);
				continue;
			}
			else{
				printf("%d\n",dfs(l,r,ma[x]));
			}

		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a);
		}
		a=((a)*(a));
		b>>=1;
	}
	return ans;
}

int dfs(int l,int r,vector<int>& v){
	if(r<l)
		return -1;
	if(binary_search(v.begin(),v.end(),l)==false)
		return l;
	if(binary_search(v.begin(),v.end(),r)==false)
		return r;
	int ind1 = lower_bound(v.begin(),v.end(),l) - v.begin();
	int ind2 = lower_bound(v.begin(),v.end(),r) - v.begin();
	if(ind2 - ind1 == r - l)
		return -1;
	int mid = ((l+r)/2);
	ind1 = dfs(l,mid,v);
	if(ind1!=-1)
		return ind1;
	return dfs(mid + 1,r,v);
}

int main() {
	IOS;
	ll t=1;
	//cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		int a[n];
		vector<int> ma[1000005];
		for(int i=0;i<n;i++){
			cin>>a[i];
			ma[a[i]].push_back(i + 1);
		}
		while(m--){
			int l,r,x;
			cin>>l>>r>>x;
			if(ma[x].size()==0){
				cout<<l<<endl;
				continue;
			}
			int ans = dfs(l,r,ma[x]);
			printf("%d\n", ans);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a);
		}
		a=((a)*(a));
		b>>=1;
	}
	return ans;
}

int dfs(int l,int r,vector<int>& v){
	if(r<l)
		return -1;
	if(binary_search(v.begin(),v.end(),l)==false)
		return l;
	if(binary_search(v.begin(),v.end(),r)==false)
		return r;
	int ind1 = lower_bound(v.begin(),v.end(),l) - v.begin();
	int ind2 = lower_bound(v.begin(),v.end(),r) - v.begin();
	if(ind2 - ind1 == r - l)
		return -1;
	int mid = ((l+r)/2);
	ind1 = dfs(l,mid,v);
	if(ind1!=-1)
		return ind1;
	return dfs(mid + 1,r,v);
}

int main() {
	IOS;
	ll t=1;
	//cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		int a[n];
		vector<int> ma[1000005];
		for(int i=0;i<n;i++){
			cin>>a[i];
			ma[a[i]].push_back(i + 1);
		}
		while(m--){
			int l,r,x;
			cin>>l>>r>>x;
			if(ma[x].size()==0){
				cout<<l<<endl;
				continue;
			}
			cout<<""<<dfs(l,r,ma[x])<<endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,ll> ii;
typedef pair <ii,int> iii;

const int inf = 0x3F3F3F3F;
const ull mod = 998244353;

int pos[200005], v[200005];

void solve(){
	int n,q,x,l,r;
	cin >> n >> q;
	for(int i = 1; i <= n; i++){
		cin >> v[i];
		if(v[i] != v[i-1])pos[i] = i-1;
		else pos[i] = pos[i-1];
	}
	while(q--){
		cin >> l >> r >> x;
		if(v[r] != x){
			cout << r << endl;
		}else{
			if(pos[r] >= l)cout << pos[r] << endl;
			else cout << -1 << endl;
		}
	}
}

int main(){
	fastio;
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,ll> ii;
typedef pair <ii,int> iii;

const int inf = 0x3F3F3F3F;
const ull mod = 998244353;

vi pos[1000005];

void solve(){
	set<int> st;
	set<int>::iterator it;
	int n,q,l,r,x,ans,aux;
	cin >> n >> q;
	for(int i = 1; i <= n; i++){
		cin >> x;
		pos[x].pb(i);
		st.insert(x);
	}
	while(q--){
		cin >> l >> r >> x;
		ans = -1;
		it = st.begin();
		while(it != st.end()){
			if((*it) != x){
				aux = lower_bound(all(pos[(*it)]), l) - pos[(*it)].begin();
				//cout << (*it) <<" " << pos[(*it)][aux] << endl;
				if(aux < sz(pos[(*it)])){
					aux = pos[(*it)][aux];
					if(aux >= l and aux <= r){
						ans = aux;
						break;
					}
				}
			}
			it++;
		}
		cout << ans << endl;
	}
}

int main(){
	fastio;
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,ll> ii;
typedef pair <ii,int> iii;

const int inf = 0x3F3F3F3F;
const ull mod = 998244353;

int pos[200005], v[200005];

void solve(){
	int n,q,x,l,r,ans;
	scanf("%d%d",&n,&q);
	for(int i = 1; i <= n; i++){
		scanf("%d", &v[i]);
		if(v[i] != v[i-1])pos[i] = i-1;
		else pos[i] = pos[i-1];
	}
	while(q--){
		scanf("%d%d%d", &l, &r, &x);
		if(v[r] != x)
			ans = r;
		else{
			if(pos[r] >= l)ans = pos[r];
			else ans = -1;
		}
		printf("%d\n", ans);
	}
}

int main(){
	fastio;
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,ll> ii;
typedef pair <ii,int> iii;

const int inf = 0x3F3F3F3F;
const ull mod = 998244353;

vi pos[1000005];

void solve(){
	set<int> st;
	set<int>::iterator it;
	int n,q,l,r,x,ans,aux;
	scanf("%d%d", &n, &q);
	for(int i = 1; i <= n; i++){
		scanf("%d", &x);
		pos[x].pb(i);
		st.insert(x);
	}
	while(q--){
		scanf("%d%d%d", &l, &r, &x);
		ans = -1;
		it = st.begin();
		while(it != st.end()){
			if((*it) != x){
				aux = lower_bound(all(pos[(*it)]), l) - pos[(*it)].begin();
				//cout << (*it) <<" " << pos[(*it)][aux] << endl;
				if(aux < sz(pos[(*it)])){
					aux = pos[(*it)][aux];
					if(aux >= l and aux <= r){
						ans = aux;
						break;
					}
				}
			}
			it++;
		}
		printf("%d\n", ans);
	}
}

int main(){
	//fastio;
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,ll> ii;
typedef pair <ii,int> iii;

const int inf = 0x3F3F3F3F;
const ull mod = 998244353;

vi pos[1000005];

void solve(){
	set<int> st;
	set<int>::iterator it;
	int n,q,l,r,x,ans,aux;
	scanf("%d%d", &n, &q);
	for(int i = 1; i <= n; i++){
		scanf("%d", &x);
		pos[x].pb(i);
		st.insert(x);
	}
	while(q--){
		scanf("%d%d%d", &l, &r, &x);
		ans = -1;
		it = st.end();
		while(it != st.begin()){
			it--;
			if((*it) != x){
				aux = lower_bound(all(pos[(*it)]), l) - pos[(*it)].begin();
				//cout << (*it) <<" " << pos[(*it)][aux] << endl;
				if(aux < sz(pos[(*it)])){
					aux = pos[(*it)][aux];
					if(aux >= l and aux <= r){
						ans = aux;
						break;
					}
				}
			}

		}
		printf("%d\n", ans);
	}
}

int main(){
	//fastio;
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,ll> ii;
typedef pair <ii,int> iii;

const int inf = 0x3F3F3F3F;
const ull mod = 998244353;

vi pos[200005];

void solve(){
	set<int> st;
	set<int>::iterator it;
	int n,q,l,r,x,ans,aux;
	cin >> n >> q;
	for(int i = 1; i <= n; i++){
		cin >> x;
		pos[x].pb(i);
		st.insert(x);
	}
	while(q--){
		cin >> l >> r >> x;
		ans = -1;
		it = st.begin();
		while(it != st.end()){
			if((*it) != x){
				aux = lower_bound(all(pos[(*it)]), l) - pos[(*it)].begin();
				//cout << (*it) <<" " << pos[(*it)][aux] << endl;
				if(aux < sz(pos[(*it)])){
					aux = pos[(*it)][aux];
					if(aux >= l and aux <= r){
						ans = aux;
						break;
					}
				}
			}
			it++;
		}
		cout << ans << endl;
	}
}

int main(){
	fastio;
	solve();
	return 0;
}


#include <iostream>
using namespace std;

int main() {

    int n, m; cin >> n >> m;

    int *data = new int[n];
    int *helper = new int[n];
    cin >> data[0]; helper[0] = -1;
    for (int i = 1; i < n; i++) {
        cin >> data[i];
        if (data[i] == data[i - 1]) {
            helper[i] = helper[i - 1];
        } else {
            helper[i] = i - 1;
        }
    }

    for (int k = 0; k < m; k++) {
        int from; cin >> from; from--;
        int to; cin >> to; to--;
        int number; cin >> number;
        if (data[to] != number) {
            cout << to + 1 << endl;
            continue;
        }
        if (helper[to] >= from) {
            cout << helper[to] + 1 << endl;
        } else {
            cout << -1 << endl;
        }
    }

    return 0;
}


#include <iostream>
using namespace std;

int main() {
    long long n, m; cin >> n >> m;
    long long *data = new long long[n];
    long long *helper = new long long[n];
    cin >> data[0]; helper[0] = -1;
    for (long long i = 1; i < n; i++) {
        cin >> data[i];
        if (data[i] == data[i - 1]) {
            helper[i] = helper[i - 1];
        } else {
            helper[i] = i - 1;
        }
    }
    for (long long k = 0; k < m; k++) {
        long long from; cin >> from; from--;
        long long to; cin >> to; to--;
        long long number; cin >> number;
        if (data[to] != number) {
            cout << to + 1 << endl;
            continue;
        }
        if (helper[to] >= from) {
            cout << helper[to] + 1 << endl;
        } else {
            cout << -1 << endl;
        }
    }
    return 0;
}


#include <iostream>
using namespace std;

int main() {

    int n, m;
    scanf("%d%d", &n, &m);

    int *data = new int[n];
    int *helper = new int[n];
    scanf("%d", data);
    helper[0] = -1;
    for (int i = 1; i < n; i++) {
        scanf("%d", data + i);
        if (data[i] == data[i - 1]) {
            helper[i] = helper[i - 1];
        } else {
            helper[i] = i - 1;
        }
    }

    for (int k = 0; k < m; k++) {
        int from, to, number;
        scanf("%d%d%d", &from, &to, &number);
        from--; to--;
        if (data[to] != number) {
            printf("%d\n", to+1);
            continue;
        }
        if (helper[to] >= from) {
            printf("%d\n", helper[to]+1);
        } else {
            printf("%d\n", -1);;
        }
    }

    return 0;
}


#include <iostream>
using namespace std;

int main() {

    int n, m; cin >> n >> m;

    int *data = new int[n];
    int *helper = new int[n];
    cin >> data[0]; helper[0] = -1;
    for (int i = 1; i < n; i++) {
        cin >> data[i];
        if (data[i] == data[i - 1]) {
            helper[i] = helper[i - 1];
        } else {
            helper[i] = i - 1;
        }
    }

    for (int k = 0; k < m; k++) {
        int from, to, number;
        cin >> from >> to >> number;
        from--; to--;
        if (data[to] != number) {
            cout << to + 1 << endl;
            continue;
        }
        if (helper[to] >= from) {
            cout << helper[to] + 1 << endl;
        } else {
            cout << -1 << endl;
        }
    }

    return 0;
}


#include <iostream>
using namespace std;

int main() {

    long long n, m; cin >> n >> m;

    long long *data = new long long[n];
    long long *helper = new long long[n];
    cin >> data[0]; helper[0] = -1;
    for (long long i = 1; i < n; i++) {
        cin >> data[i];
        if (data[i] == data[i - 1]) {
            helper[i] = helper[i - 1];
        } else {
            helper[i] = i - 1;
        }
    }

    for (long long k = 0; k < m; k++) {
        long long from; cin >> from; from--;
        long long to; cin >> to; to--;
        long long number; cin >> number;
        if (data[to] != number) {
            cout << to + 1 << endl;
            continue;
        }
        if (helper[to] >= from) {
            cout << helper[to] + 1 << endl;
        } else {
            cout << -1 << endl;
        }
    }

    return 0;
}