// rc.cpp : Defines the entry point for the console application.
//

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <functional>

#define PI 3.14159265358979323846

using namespace std;

typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long long uint64;
typedef long long sint64;

int main(int argc, char* argv[])
{
    uint n, m;
    cin >> n >> m;

    map<uint64, vector<pair<uint, uint>>> v;

    uint ip = 0;
    uint64 p = -1,
           a = 0;

    cin >> p;
    for (uint i = 1; i <= n; ++i)
    {
        if (i < n)
            cin >> a;

        if (i == n || a != p)
        {
            pair<uint, uint> z(ip, i - 1);
            v[p].push_back(z);
            ip = i;
        }

        p = a;
    }

    for (uint i = 0; i < m; ++i)
    {
        uint l, r;
        uint64 x;
        cin >> l >> r >> x;

        map<uint64, vector<pair<uint, uint>>>::iterator it = v.find(x);
        if (it == v.end())
            printf("%u\n", l);
        else
        {
            --l, --r;
            vector<pair<uint, uint>>& qv = it->second;
            vector<pair<uint, uint>>::iterator jt = lower_bound(qv.begin(), qv.end(), make_pair(l, (uint)0));
            if (jt != qv.begin())
                --jt;

            bool pr = false;
            for (uint j = 0; j < 3 && jt != qv.end(); ++j, ++jt)
            {
                if (jt->first <= l && jt->second >= r)
                {
                    printf("-1\n");
                    pr = true;
                    break;
                }
                else if (jt->second >= l && jt->second < r)
                {
                    printf("%u\n", jt->second + 2);
                    pr = true;
                    break;
                }
                else if(jt->first <= r && jt->first > l)
                {
                    printf("%u\n", jt->first);
                    pr = true;
                    break;
                }
                else if (jt->first > l && jt->second < r)
                {
                    printf("%u\n", jt->first);
                    pr = true;
                    break;
                }
            }

            if (!pr)
                printf("%u\n", l + 1);
        }
    }

    return 0;
}


// rc.cpp : Defines the entry point for the console application.
//

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <functional>

#define PI 3.14159265358979323846

using namespace std;

typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long long uint64;
typedef long long sint64;

int main(int argc, char* argv[])
{
    uint n, m;
    cin >> n >> m;

    map<uint64, vector<pair<uint, uint>>> v;

    uint ip = 0;
    uint64 p = -1,
           a = 0;

    cin >> p;
    for (uint i = 1; i <= n; ++i)
    {
        if (i < n)
            cin >> a;

        if (i == n || a != p)
        {
            pair<uint, uint> z(ip, i - 1);
            v[p].push_back(z);
            ip = i;
        }

        p = a;
    }

    for (uint i = 0; i < m; ++i)
    {
        uint l, r;
        uint64 x;
        cin >> l >> r >> x;

        map<uint64, vector<pair<uint, uint>>>::iterator it = v.find(x);
        if (it == v.end())
            printf("%u\n", l);
        else
        {
            --l, --r;
            vector<pair<uint, uint>>& qv = it->second;
            vector<pair<uint, uint>>::iterator jt = lower_bound(qv.begin(), qv.end(), make_pair(l, (uint)0));
            if (jt == qv.end())
                --jt;

            if (jt->first <= l && jt->second >= r)
                printf("-1\n");
            else
            {
                if (jt->first > l)
                    printf("%u\n", l + 1);
                else
                    printf("%u\n", jt->second + 2);
            }
        }
    }

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#include <functional>
#include <time.h>
#include <cmath>
#include <assert.h>
#include <deque>
#include <iomanip>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii pair<int, pair<int, int> >
#define plll pair<ll, pair<ll, ll> >

ll EPS = 1000000007;
const int INF = 1000000000;
double PI = 3.14159265358979323846;
const int MAXN = 1000040;

ll abss(ll h) {
	return max(h, -h);
}

double fabss(double h) {
	return max(h, -h);
}

ll ceill(ll x, ll y) {
	if (x % y != 0) return (x / y) + 1;
	return x / y;
}

string itos(ll num) {
	string str = "";
	if (num == 0) return "0";
	while (num != 0) {
		str += ((num % 10) + '0');
		num /= 10;
	}
	reverse(str.begin(), str.end());
	return str;
}

ll sstoi(string num) {
	ll count = 1;
	for (int i = 0; i < (int)num.size() - 1; i++) {
		count *= 10;
	}
	ll ans = 0;
	for (int i = 0; i < (int)num.size(); i++) {
		ans += (num[i] - '0') * count;
		count /= 10;

	}
	return ans;
}

int n, m, k;

pair<int, int> a[MAXN];
pair<int, int> t[MAXN];
pair<int, int> t2[MAXN];
int c[MAXN];

void build1 (int v, int tl, int tr) {
	if (tl == tr)
		t[v] = a[tl];
	else {
		int tm = (tl + tr) / 2;
		build1 (v*2, tl, tm);
		build1 (v*2+1, tm+1, tr);
		if (t[v * 2] > t[v * 2 + 1])
		{
			t[v] = t[v*2];
		}
		else
		{
			t[v] = t[v * 2 + 1];
		}
	}
}

void build2 (int v, int tl, int tr) {
	if (tl == tr)
		t2[v] = a[tl];
	else {
		int tm = (tl + tr) / 2;
		build1 (v*2, tl, tm);
		build1 (v*2+1, tm+1, tr);
		if (t[v * 2] < t[v * 2 + 1])
		{
			t2[v] = t2[v*2];
		}
		else
		{
			t2[v] = t2[v * 2 + 1];
		}
	}
}

pair<int, int> sum (int v, int tl, int tr, int l, int r) {
	if (l > r)
		return mp(0, 0);
	if (l == tl && r == tr)
		return t[v];
	int tm = (tl + tr) / 2;
	pii t1 = sum (v*2, tl, tm, l, min(r,tm));
	pii t2 = sum (v*2+1, tm+1, tr, max(l,tm+1), r);
	if (t1.first > t2.first)
	{
		return t1;
	}
	else
	{
		return t2;
	}
}

pair<int, int> sum2 (int v, int tl, int tr, int l, int r) {
	if (l > r)
		return mp(EPS, EPS);
	if (l == tl && r == tr)
		return t2[v];
	int tm = (tl + tr) / 2;
	pii t1 = sum2 (v*2, tl, tm, l, min(r,tm));
	pii t2 = sum2 (v*2+1, tm+1, tr, max(l,tm+1), r);
	if (t1.first < t2.first)
	{
		return t1;
	}
	else
	{
		return t2;
	}
}

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first;
		a[i].second = i;
	}
	int l, r, x;
	build1(1, 0, n - 1);
	build2(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d %d", &l, &r, &x);
		pii t1 = sum(1, 0, n - 1, l - 1, r - 1);
		pii t2 = sum2(1, 0, n - 1, l - 1, r - 1);
		if (t1.first == t2.first && x == t1.first)
		{
			printf("%d\n", -1);
		}
		else
		{
			if (t1.first != x)
			{
				printf("%d\n", t1.second + 1);
			}
			else
			{
				printf("%d\n", t2.second + 1);
			}
		}
	}
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#include <functional>
#include <time.h>
#include <cmath>
#include <assert.h>
#include <deque>
#include <iomanip>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii pair<int, pair<int, int> >
#define plll pair<ll, pair<ll, ll> >

ll EPS = 1000000007;
const int INF = 1000000000;
double PI = 3.14159265358979323846;
const int MAXN = 1000040;

ll abss(ll h) {
	return max(h, -h);
}

double fabss(double h) {
	return max(h, -h);
}

ll ceill(ll x, ll y) {
	if (x % y != 0) return (x / y) + 1;
	return x / y;
}

string itos(ll num) {
	string str = "";
	if (num == 0) return "0";
	while (num != 0) {
		str += ((num % 10) + '0');
		num /= 10;
	}
	reverse(str.begin(), str.end());
	return str;
}

ll sstoi(string num) {
	ll count = 1;
	for (int i = 0; i < (int)num.size() - 1; i++) {
		count *= 10;
	}
	ll ans = 0;
	for (int i = 0; i < (int)num.size(); i++) {
		ans += (num[i] - '0') * count;
		count /= 10;

	}
	return ans;
}

int n, m, k;

pair<int, int> a[MAXN];
pair<int, int> t[MAXN];
pair<int, int> t2[MAXN];
int c[MAXN];

void build1 (int v, int tl, int tr) {
	if (tl == tr)
		t[v] = a[tl];
	else {
		int tm = (tl + tr) / 2;
		build1 (v*2, tl, tm);
		build1 (v*2+1, tm+1, tr);
		if (t[v * 2] > t[v * 2 + 1])
		{
			t[v] = t[v*2];
		}
		else
		{
			t[v] = t[v * 2 + 1];
		}
	}
}

void build2 (int v, int tl, int tr) {
	if (tl == tr)
		t2[v] = a[tl];
	else {
		int tm = (tl + tr) / 2;
		build2 (v*2, tl, tm);
		build2 (v*2+1, tm+1, tr);
		if (t[v * 2] < t[v * 2 + 1])
		{
			t2[v] = t2[v*2];
		}
		else
		{
			t2[v] = t2[v * 2 + 1];
		}
	}
}

pair<int, int> sum (int v, int tl, int tr, int l, int r) {
	if (l > r)
		return mp(0, 0);
	if (l == tl && r == tr)
		return t[v];
	int tm = (tl + tr) / 2;
	pii t1 = sum (v*2, tl, tm, l, min(r,tm));
	pii t2 = sum (v*2+1, tm+1, tr, max(l,tm+1), r);
	if (t1.first > t2.first)
	{
		return t1;
	}
	else
	{
		return t2;
	}
}

pair<int, int> sum2 (int v, int tl, int tr, int l, int r) {
	if (l > r)
		return mp(EPS, EPS);
	if (l == tl && r == tr)
		return t2[v];
	int tm = (tl + tr) / 2;
	pii t1 = sum2 (v*2, tl, tm, l, min(r,tm));
	pii t2 = sum2 (v*2+1, tm+1, tr, max(l,tm+1), r);
	if (t1.first < t2.first)
	{
		return t1;
	}
	else
	{
		return t2;
	}
}

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first;
		a[i].second = i;
	}
	int l, r, x;
	build1(1, 0, n - 1);
	build2(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d %d", &l, &r, &x);
		pii t1 = sum(1, 0, n - 1, l - 1, r - 1);
		pii t2 = sum2(1, 0, n - 1, l - 1, r - 1);
		if (t1.first == t2.first && x == t1.first)
		{
			printf("%d\n", -1);
		}
		else
		{
			if (t1.first != x)
			{
				printf("%d\n", t1.second + 1);
			}
			else
			{
				printf("%d\n", t2.second + 1);
			}
		}
	}
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#include <functional>
#include <time.h>
#include <cmath>
#include <assert.h>
#include <deque>
#include <iomanip>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii pair<int, pair<int, int> >
#define plll pair<ll, pair<ll, ll> >

ll EPS = 1000000007;
const int INF = 1000000000;
double PI = 3.14159265358979323846;
const int MAXN = 1000040;

ll abss(ll h) {
	return max(h, -h);
}

double fabss(double h) {
	return max(h, -h);
}

ll ceill(ll x, ll y) {
	if (x % y != 0) return (x / y) + 1;
	return x / y;
}

string itos(ll num) {
	string str = "";
	if (num == 0) return "0";
	while (num != 0) {
		str += ((num % 10) + '0');
		num /= 10;
	}
	reverse(str.begin(), str.end());
	return str;
}

ll sstoi(string num) {
	ll count = 1;
	for (int i = 0; i < (int)num.size() - 1; i++) {
		count *= 10;
	}
	ll ans = 0;
	for (int i = 0; i < (int)num.size(); i++) {
		ans += (num[i] - '0') * count;
		count /= 10;

	}
	return ans;
}

int n, m, k;

pair<int, int> a[MAXN];
pair<int, int> t[MAXN];
pair<int, int> t2[MAXN];
int c[MAXN];

void build1 (int v, int tl, int tr) {
	if (tl == tr)
		t[v] = a[tl];
	else {
		int tm = (tl + tr) / 2;
		build1 (v*2, tl, tm);
		build1 (v*2+1, tm+1, tr);
		if (t[v * 2] > t[v * 2 + 1])
		{
			t[v] = t[v*2];
		}
		else
		{
			t[v] = t[v * 2 + 1];
		}
	}
}

void build2 (int v, int tl, int tr) {
	if (tl == tr)
		t2[v] = a[tl];
	else {
		int tm = (tl + tr) / 2;
		build1 (v*2, tl, tm);
		build1 (v*2+1, tm+1, tr);
		if (t[v * 2] < t[v * 2 + 1])
		{
			t2[v] = t2[v*2];
		}
		else
		{
			t2[v] = t2[v * 2 + 1];
		}
	}
}

pair<int, int> sum (int v, int tl, int tr, int l, int r) {
	if (l > r)
		return mp(0, 0);
	if (l == tl && r == tr)
		return t[v];
	int tm = (tl + tr) / 2;
	pii t1 = sum (v*2, tl, tm, l, min(r,tm));
	pii t2 = sum (v*2+1, tm+1, tr, max(l,tm+1), r);
	if (t1.first > t2.first)
	{
		return t1;
	}
	else
	{
		return t2;
	}
}

pair<int, int> sum2 (int v, int tl, int tr, int l, int r) {
	if (l > r)
		return mp(EPS, EPS);
	if (l == tl && r == tr)
		return t2[v];
	int tm = (tl + tr) / 2;
	pii t1 = sum (v*2, tl, tm, l, min(r,tm));
	pii t2 = sum (v*2+1, tm+1, tr, max(l,tm+1), r);
	if (t1.first < t2.first)
	{
		return t1;
	}
	else
	{
		return t2;
	}
}

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first;
		a[i].second = i;
	}
	int l, r, x;
	build1(1, 0, n - 1);
	build2(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d %d", &l, &r, &x);
		pii t1 = sum(1, 0, n - 1, l - 1, r - 1);
		pii t2 = sum2(1, 0, n - 1, l - 1, r - 1);
		if (t1.first == t2.first && x == t1.first)
		{
			printf("%d\n", -1);
		}
		else
		{
			if (t1.first != x)
			{
				printf("%d\n", t1.second + 1);
			}
			else
			{
				printf("%d\n", t2.second + 1);
			}
		}
	}
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#include <functional>
#include <time.h>
#include <cmath>
#include <assert.h>
#include <deque>
#include <iomanip>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii pair<int, pair<int, int> >
#define plll pair<ll, pair<ll, ll> >

ll EPS = 1000000007;
const int INF = 1000000000;
double PI = 3.14159265358979323846;
const int MAXN = 1000040;

ll abss(ll h) {
	return max(h, -h);
}

double fabss(double h) {
	return max(h, -h);
}

ll ceill(ll x, ll y) {
	if (x % y != 0) return (x / y) + 1;
	return x / y;
}

string itos(ll num) {
	string str = "";
	if (num == 0) return "0";
	while (num != 0) {
		str += ((num % 10) + '0');
		num /= 10;
	}
	reverse(str.begin(), str.end());
	return str;
}

ll sstoi(string num) {
	ll count = 1;
	for (int i = 0; i < (int)num.size() - 1; i++) {
		count *= 10;
	}
	ll ans = 0;
	for (int i = 0; i < (int)num.size(); i++) {
		ans += (num[i] - '0') * count;
		count /= 10;

	}
	return ans;
}

int n, m, k;

pair<int, int> a[MAXN];
pair<int, int> t[MAXN];
pair<int, int> t2[MAXN];
int c[MAXN];

void build1 (int v, int tl, int tr) {
	if (tl == tr)
		t[v] = a[tl];
	else {
		int tm = (tl + tr) / 2;
		build1 (v*2, tl, tm);
		build1 (v*2+1, tm+1, tr);
		if (t[v * 2] > t[v * 2 + 1])
		{
			t[v] = t[v*2];
		}
		else
		{
			t[v] = t[v * 2 + 1];
		}
	}
}

void build2 (int v, int tl, int tr) {
	if (tl == tr)
		t2[v] = a[tl];
	else {
		int tm = (tl + tr) / 2;
		build2 (v*2, tl, tm);
		build2 (v*2+1, tm+1, tr);
		if (t2[v * 2] < t2[v * 2 + 1])
		{
			t2[v] = t2[v*2];
		}
		else
		{
			t2[v] = t2[v * 2 + 1];
		}
	}
}

pair<int, int> sum (int v, int tl, int tr, int l, int r) {
	if (l > r)
		return mp(0, 0);
	if (l == tl && r == tr)
		return t[v];
	int tm = (tl + tr) / 2;
	pii t1 = sum (v*2, tl, tm, l, min(r,tm));
	pii t2 = sum (v*2+1, tm+1, tr, max(l,tm+1), r);
	if (t1.first > t2.first)
	{
		return t1;
	}
	else
	{
		return t2;
	}
}

pair<int, int> sum2 (int v, int tl, int tr, int l, int r) {
	if (l > r)
		return mp(EPS, EPS);
	if (l == tl && r == tr)
		return t2[v];
	int tm = (tl + tr) / 2;
	pii t1 = sum2 (v*2, tl, tm, l, min(r,tm));
	pii t2 = sum2 (v*2+1, tm+1, tr, max(l,tm+1), r);
	if (t1.first < t2.first)
	{
		return t1;
	}
	else
	{
		return t2;
	}
}

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first;
		a[i].second = i;
	}
	int l, r, x;
	build1(1, 0, n - 1);
	build2(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d %d", &l, &r, &x);
		pii t1 = sum(1, 0, n - 1, l - 1, r - 1);
		pii t2 = sum2(1, 0, n - 1, l - 1, r - 1);
		if (t1.first == t2.first && x == t1.first)
		{
			printf("%d\n", -1);
		}
		else
		{
			if (t1.first != x)
			{
				printf("%d\n", t1.second + 1);
			}
			else
			{
				printf("%d\n", t2.second + 1);
			}
		}
	}
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#include <functional>
#include <time.h>
#include <cmath>
#include <assert.h>
#include <deque>
#include <iomanip>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii pair<int, pair<int, int> >
#define plll pair<ll, pair<ll, ll> >

ll EPS = 1000000007;
const int INF = 1000000000;
double PI = 3.14159265358979323846;
const int MAXN = 1000040;

ll abss(ll h) {
	return max(h, -h);
}

double fabss(double h) {
	return max(h, -h);
}

ll ceill(ll x, ll y) {
	if (x % y != 0) return (x / y) + 1;
	return x / y;
}

string itos(ll num) {
	string str = "";
	if (num == 0) return "0";
	while (num != 0) {
		str += ((num % 10) + '0');
		num /= 10;
	}
	reverse(str.begin(), str.end());
	return str;
}

ll sstoi(string num) {
	ll count = 1;
	for (int i = 0; i < (int)num.size() - 1; i++) {
		count *= 10;
	}
	ll ans = 0;
	for (int i = 0; i < (int)num.size(); i++) {
		ans += (num[i] - '0') * count;
		count /= 10;

	}
	return ans;
}

int n, m, k;

pair<int, int> a[MAXN];
pair<int, int> t[MAXN];
pair<int, int> t2[MAXN];
int c[MAXN];

void build1 (int v, int tl, int tr) {
	if (tl == tr)
		t[v] = a[tl];
	else {
		int tm = (tl + tr) / 2;
		build1 (v*2, tl, tm);
		build1 (v*2+1, tm+1, tr);
		if (t[v * 2] > t[v * 2 + 1])
		{
			t[v] = t[v*2];
		}
		else
		{
			t[v] = t[v * 2 + 1];
		}
	}
}

void build2 (int v, int tl, int tr) {
	if (tl == tr)
		t2[v] = a[tl];
	else {
		int tm = (tl + tr) / 2;
		build1 (v*2, tl, tm);
		build1 (v*2+1, tm+1, tr);
		if (t[v * 2] < t[v * 2 + 1])
		{
			t2[v] = t2[v*2];
		}
		else
		{
			t2[v] = t2[v * 2 + 1];
		}
	}
}

pair<int, int> sum (int v, int tl, int tr, int l, int r) {
	if (l > r)
		return mp(-1, -1);
	if (l == tl && r == tr)
		return t[v];
	int tm = (tl + tr) / 2;
	pii t1 = sum (v*2, tl, tm, l, min(r,tm));
	pii t2 = sum (v*2+1, tm+1, tr, max(l,tm+1), r);
	if (t1.first > t2.first)
	{
		return t1;
	}
	else
	{
		return t2;
	}
}

pair<int, int> sum2 (int v, int tl, int tr, int l, int r) {
	if (l > r)
		return mp(-1, -1);
	if (l == tl && r == tr)
		return t2[v];
	int tm = (tl + tr) / 2;
	pii t1 = sum (v*2, tl, tm, l, min(r,tm));
	pii t2 = sum (v*2+1, tm+1, tr, max(l,tm+1), r);
	if (t1.first < t2.first)
	{
		return t1;
	}
	else
	{
		return t2;
	}
}

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first;
		a[i].second = i;
	}
	int l, r, x;
	build1(1, 0, n - 1);
	build2(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		cin >> l >> r >> x;
		pii t1 = sum(1, 0, n - 1, l - 1, r - 1);
		pii t2 = sum2(1, 0, n - 1, l - 1, r - 1);
		if (t1.first == t2.first && x == t1.first)
		{
			printf("%d\n", -1);
		}
		else
		{
			if (t1.first != x)
			{
				printf("%d\n", t1.second + 1);
			}
			else
			{
				printf("%d\n", t2.second + 1);
			}
		}
	}
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
	int n, q, i, l, r, k;
	vector<int> A, B;
	cin >> n >> q;
	A = vector<int>(n + 1);
	B = vector<int>(n + 1, -1);
	for (i = 1; i <= n; ++i)
		cin >> A[i];
	for (i = 2; i <= n; ++i)
	{
		if (A[i] == A[i - 1])
			B[i] = B[i - 1];
		else B[i] = i - 1;
	}
	for (i = 0; i < q; ++i)
	{
		cin >> l >> r >> k;
		if (A[r] != k)
			cout << r << endl;
		else
		{
			if (B[r] >= l)
				cout << B[r] << endl;
			else cout << "-1" << endl;
		}
	}
	return 0;
}


#include <stdio.h>
#include <vector>
using namespace std;
int main()
{
	int n, q, i, l, r, k;
	vector<int> A, B;
	scanf_s("%d%d",&n,&q);
	A = vector<int>(n + 1);
	B = vector<int>(n + 1, -1);
	for (i = 1; i <= n; ++i)
		scanf_s("%d", &A[i]);
	for (i = 2; i <= n; ++i)
	{
		if (A[i] == A[i - 1])
			B[i] = B[i - 1];
		else B[i] = i - 1;
	}
	for (i = 0; i < q; ++i)
	{
		scanf_s("%d%d%d", &l, &r, &k);
		if (A[r] != k)
			printf_s("%d\n", r);
		else
		{
			if (B[r] >= l)
				printf_s("%d\n",B[r]);
			else printf_s("-1\n");
		}
	}
	return 0;
}


#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <string>
#include <time.h>

typedef long long ll;

int a[200001];
int pos[200001];

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n;
	int m;

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

	for (int i = 1; i <= n; i++) {

		scanf("%d", &a[i]);
		if (a[i - 1] != a[i])
			pos[i] = i - 1;
		else
			pos[i] = pos[i - 1];
	}

	for (int i = 0; i < m; i++) {

		int l;
		int r;
		int x;

		scanf("%d%d%d", &l, &r, &x);

		if (a[r] != x)
			printf("%d\n", r);
		else
			if (pos[r] >= l)
				printf("%d\n", pos[r]);
			else
				printf("-1\n");

	}

	return 0;
}


#pragma warning(disable:4996)
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <iostream>
#include <stack>
#include <assert.h>
//#pragma comment(linker, "/STACK:202400000,202400000") //不需要申请系统栈
using namespace std;

struct Node
{
	int l, r, mx, mn, vis1,vis2;
}a[200000 * 8];
int x, y, sji;

void createtree(int l, int r, int num)
{
	int i, j, mid;
	a[num].l = l;
	a[num].r = r;
	if (l == r)
	{
		scanf("%d", &a[num].mx);
		a[num].mn = a[num].mx;
		a[num].vis1 = a[num].vis2 = l;
		return;
	}
	mid = (l + r) / 2;
	createtree(l, mid, num * 2);
	createtree(mid + 1, r, num * 2 + 1);
	a[num].mn = min(a[num*2].mn, a[num * 2 + 1].mn);
	a[num].mx = max(a[num * 2].mx, a[num * 2 + 1].mx);
	if (a[num].mn == a[num].mx)
	{
		a[num].vis1 = a[num].vis2 = a[num * 2].vis1;
	}
	else
	{
		if (a[num * 2].mx > a[num * 2 + 1].mx)a[num].vis1 = a[num * 2].vis1;
		else a[num].vis1 = a[num * 2 + 1].vis1;
		if (a[num * 2].mn < a[num * 2 + 1].mn)a[num].vis2 = a[num * 2].vis2;
		else a[num].vis2 = a[num * 2 + 1].vis2;
	}
}

int seach(int l, int r, int num)
{
	int res, mid, carry;
	if (l >= x && r <= y)
	{
		if (a[num].mx == a[num].mn && a[num].mx == sji)return -1;
		if (a[num].mx != sji)return a[num].vis1;
		else return a[num].vis2;
	}
	mid = (l + r) / 2;
	if (x <= mid)
	{
		carry = seach(l, mid, num * 2);
		if (carry != -1)return carry;
	}
	if (y>mid)
	{
		carry = seach(mid + 1, r, num * 2 + 1);
		if (carry != -1)return carry;
	}
	return -1;
}

int main()
{
	int n, m, i, j, ji, q, ji1, ji2;
	while (~scanf("%d %d", &n, &m))
	{
		createtree(1, n, 1);
		while (m--)
		{
			scanf("%d %d %d", &ji1, &ji2, &ji);
			sji = ji;
			x = ji1, y = ji2;
			printf("%d\n", seach(1, n, 1));
		}
	}
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;
    scanf("%d","%d",&m,&n);
    int *mas=new int [m];
    int *ml=new int [m];
    for(int i=0; i<m; i++)
        scanf("%d", mas[i]);
    ml[0]=-1;
    for(int i=1; i<m; i++)
    {
        if(mas[i]==mas[i-1])
            ml[i]=ml[i-1];
        else
            ml[i]=i-1;
    }
    int a,b,c;
    while(n--)
    {
        scanf("%d","%d","%d",a,b,c);
        a--;
        b--;
        if (mas[b]==c)
            if (ml[b]>=a)
                printf(%d,ml[b]+1);
            else
                printf(%d,-1);
        else
            printf("%d",b+1);
        cout << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;
    cin >> m >> n;
    int *mas=new int [m];
    int *ml=new int [m];
    for(int i=0; i<m; i++)
        cin >> mas[i];
    ml[0]=-1;
    for(int i=1; i<m; i++)
    {
        if(mas[i]==mas[i-1])
            ml[i]=ml[i-1];
        else
            ml[i]=i-1;
    }
    int a,b,c;
    while(n--)
    {
        cin >> a >> b >> c;
        a--;
        b--;
        if (mas[b]==c)
            if (ml[b]>=a)
                cout << ml[b];
            else
                cout << -1;
        else
            cout << b+1;
        cout << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;
    scanf("%d%d",&m,&n);
    int *mas=new int [m];
    int *ml=new int [m];
    for(int i=0; i<m; i++)
        scanf("%d", &mas[i]);
    ml[0]=-1;
    for(int i=1; i<m; i++)
    {
        if(mas[i]==mas[i-1])
            ml[i]=ml[i-1];
        else
            ml[i]=i-1;
    }
    int a,b,c;
    while(n--)
    {
        scanf("%d%d%d",&a,&b,&c);
        a--;
        b--;
        if (mas[b]==c)
            if (ml[b]>=a)
                printf("%d",ml[b]+1);
            else
                printf("-1");
        else
            printf("%d",b+1);
        cout << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;
    cin >> m >> n;
    int *mas=new int [m];
    int *ml=new int [m];
    for(int i=0; i<m; i++)
        cin >> mas[i];
    ml[0]=-1;
    for(int i=1; i<m; i++)
    {
        if(mas[i]==mas[i-1])
            ml[i]=ml[i-1];
        else
            ml[i]=i-1;
    }
    int a,b,c;
    while(n--)
    {
        cin >> a >> b >> c;
        a--;
        b--;
        if (mas[b]==c)
            if (ml[b]>=a)
                cout << ml[b]+1;
            else
                cout << -1;
        else
            cout << b+1;
        cout << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,m;
    scanf("%d%d",&m,&n);
    int *mas=new int [m];
    int *ml=new int [m];
    for(int i=0; i<m; i++)
        scanf("%d", mas[i]);
    ml[0]=-1;
    for(int i=1; i<m; i++)
    {
        if(mas[i]==mas[i-1])
            ml[i]=ml[i-1];
        else
            ml[i]=i-1;
    }
    int a,b,c;
    while(n--)
    {
        scanf("%d%d%d",&a,&b,&c);
        a--;
        b--;
        if (mas[b]==c)
            if (ml[b]>=a)
                printf("%d",ml[b]+1);
            else
                printf("%d",-1);
        else
            printf("%d",b+1);
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>

#define mp make_pair
#define pb push_back
#define sz(a) static_cast<int>((a).size())
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < n; ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> edge;

const int amax = 1e6 + 10;

int main()
{

    ios::sync_with_stdio(false);

    //ifstream cin("input.txt");
    //ofstream cout("mine.txt");

    int n, q;
    cin >> n >> q;

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

    vector<int> pos[amax];

    for (int i = 0; i < n - 1; ++i) {
        if (a[i] != a[i + 1]) {
            pos[a[i]].pb(i);
        }
    }

    while (q--) {
        int l, r, x;
        cin >> l >> r >> x;
        --l, --r;
        if (a[l] != x) {
            cout << l + 1 << "\n";
            continue;
        }
        if (a[r] != x) {
            cout << r + 1 << "\n";
            continue;
        }
        int t = lower_bound(all(pos[x]), l) - pos[x].begin();
        if (t == sz(pos[x])) {
            cout << "-1\n";
            continue;
        }
        int p = pos[x][t];
        if (p < r) {
            cout << p + 2 << "\n";
        } else {
            cout << "-1\n";
        }
    }

}


#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

#define mp make_pair
#define pb push_back
#define sz(a) static_cast<int>((a).size())
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < n; ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> edge;

const int amax = (int)(1e6 + 10);

int main()
{

    //ios::sync_with_stdio(false);

    //ifstream cin("input.txt");
    //ofstream cout("mine.txt");

    int n, q;
    scanf("%d%d", &n, &q);
    //cin >> n >> q;

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        //cin >> a[i];
    }

    vector<int> pos[amax];

    for (int i = 0; i < n - 1; ++i) {
        if (a[i] != a[i + 1]) {
            pos[a[i]].pb(i);
        }
    }

    while (q--) {
        int l, r, x;
        scanf("%d%d%d", &l, &r, &x);
        //cin >> l >> r >> x;
        --l, --r;
        if (a[l] != x) {
            printf("%d\n", l + 1);
            //cout << l + 1 << "\n";
            continue;
        }
        if (a[r] != x) {
            printf("%d\n", r + 1);
            //cout << r + 1 << "\n";
            continue;
        }
        int t = lower_bound(all(pos[x]), l) - pos[x].begin();
        if (t == sz(pos[x])) {
            printf("-1\n");
            //cout << "-1\n";
            continue;
        }
        int p = pos[x][t];
        if (p < r) {
            printf("%d\n", p + 2);
            //cout << p + 2 << "\n";
        } else {
            printf("-1\n");
            //cout << "-1\n";
        }
    }

}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#include <cstring>
#include <cmath>
#include <queue>
#include <functional>
#include <cstdio>
#include <cassert>
#include <stack>

#define mp make_pair
#define mt(x,y,z) mp((x), mp((y), (z)))
#define ZERO(x) memset((x), 0, sizeof(x))
#define NEGATE(x) memset((x), 255, sizeof(x))
using namespace std;

typedef long long ll;

const int N = 2e5 + 100;

const int inf = 1e9;

int a[N], mina[N];

struct SegmentTree
{
	pair<int, int> t[N * 4];
	void build(int *a, int v, int ta, int tb)
	{
		if (ta == tb)
		{
			t[v] = mp(a[ta], ta);
			return;
		}
		int m = (ta + tb) / 2;
		build(a, v * 2, ta, m);
		build(a, v * 2 + 1, m + 1, tb);
		t[v] = max(t[v * 2], t[v * 2 + 1]);
	}
	pair<int, int> getMax(int v, int ta, int tb, int l, int r)
	{
		if (l > r) return mp(-inf, -1);
		if (l == ta && tb == r)
			return t[v];
		int m = (ta + tb) / 2;
		return max(
			getMax(v * 2, ta, m, l, min(m, r)),
			getMax(v * 2 + 1, m + 1, tb, max(m + 1, l), r)
			);
	}
};

SegmentTree A, B;

int main()
{
#ifdef XXX
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		mina[i] = -a[i];
	}

	A.build(a, 1, 0, n - 1);
	B.build(mina, 1, 0, n - 1);

	for (int i = 0; i < m; i++)
	{
		int l, r, x;
		cin >> l >> r >> x;
		l--, r--;

		pair<int, int> t = A.getMax(1, 0, n - 1, l, r);

		if (t.first != x)
		{
			cout << t.second + 1 << "\n";
			continue;
		}

		t = B.getMax(1, 0, n - 1, l, r);
		t.first = -t.first;

		if (t.first != x)
		{
			cout << t.second + 1 << "\n";
			continue;
		}

		cout << -1 << "\n";

	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#include <cstring>
#include <cmath>
#include <queue>
#include <functional>
#include <cstdio>
#include <cassert>
#include <stack>

#define mp make_pair
#define mt(x,y,z) mp((x), mp((y), (z)))
#define ZERO(x) memset((x), 0, sizeof(x))
#define NEGATE(x) memset((x), 255, sizeof(x))
using namespace std;

typedef long long ll;

const int N = 2e5 + 100;

const int inf = 1e9;

int a[N], mina[N];

struct SegmentTree
{
	pair<int, int> t[N * 4];
	void build(int *a, int v, int ta, int tb)
	{
		if (ta == tb)
		{
			t[v] = mp(a[ta], ta);
			return;
		}
		int m = (ta + tb) / 2;
		build(a, v * 2, ta, m);
		build(a, v * 2 + 1, m + 1, tb);
		t[v] = max(t[v * 2], t[v * 2 + 1]);
	}
	pair<int, int> getMax(int v, int ta, int tb, int l, int r)
	{
		if (l > r) return mp(-inf, -1);
		if (l == ta && tb == r)
			return t[v];
		int m = (ta + tb) / 2;
		return max(
			getMax(v * 2, ta, m, l, min(m, r)),
			getMax(v * 2 + 1, m + 1, tb, max(m + 1, l), r)
			);
	}
};

SegmentTree A, B;

int main()
{
#ifdef XXX
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

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

	A.build(a, 1, 0, n - 1);
	B.build(mina, 1, 0, n - 1);

	for (int i = 0; i < m; i++)
	{
		int l, r, x;
		scanf("%d %d %d", &l, &r, &x);
		l--, r--;

		pair<int, int> t = A.getMax(1, 0, n - 1, l, r);

		if (t.first != x)
		{
			printf("%d\n", t.second + 1);
			continue;
		}

		t = B.getMax(1, 0, n - 1, l, r);
		t.first = -t.first;

		if (t.first != x)
		{
			printf("%d\n", t.second + 1);
			continue;
		}

		printf("-1\n");

	}

	return 0;
}


#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<utility>
#include<map>
#include <unordered_map>
#include <bitset>
using namespace std;
typedef long long ll;
int n, m, A[200004], B[200004];
int main() {
	int i, l, r, x;
	cin >> n >> m;
	for (i = 1; i <= n; i++) {
		scanf("%d", A + i);
	}
	B[n] = n + 1;
	for (i = n - 1; i >= 1; i--) {
		if (A[i] == A[i + 1]) B[i] = B[i + 1];
		else B[i] = i + 1;
	}
	while (m-- > 0) {
		scanf("%d%d%d", &l, &r, &x);
		if (A[l] != x) {
			printf("%d\n", l);
		}
		else if (B[l] <= r) {
			printf("%d\n", B[l]);
		}
		else {
			printf("-1\n");
		}
	}
}


#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<utility>
#include<map>
#include <unordered_map>
#include <bitset>
using namespace std;
typedef long long ll;
int n, m, A[200004], B[200004];
int main() {
	int i, j, l, r, x;
	cin >> n >> m;
	for (i = 1; i <= n; i++) cin >> A[i];
	B[n] = n + 1;
	for (i = n - 1; i >= 1; i--) {
		if (A[i] == A[i + 1]) B[i] = B[i + 1];
		else B[i] = i + 1;
	}
	while (m-- > 0) {
		cin >> l >> r >> x;
		if (A[l] != x) {
			cout << l << endl;
		}
		else if (B[l] <= r) {
			cout << B[l] << endl;
		}
		else {
			cout << -1 << endl;
		}
	}
}


#-*- coding: UTF-8 -*-
'''
Created on 2016��5��4��

@author: �����
'''
n,m= raw_input().split(' ')
l = raw_input().split(' ')
for i in range(int(n)):
    l[i]=int(l[i])
r=[]
ans=[]

for i in range(int(m)):
    r = raw_input().split(' ')
    flag = 0
    if int(r[2]) not in l[int(r[0])-1:int(r[1])]:
#         print int(r[0])
        ans.append(int(r[0]))
    else:
        x = range(int(m))
#         range(int(r[0])-1:int(r[1]))
        for j in x[int(r[0])-1:int(r[1])]:
            if l[j]!=int(r[2]):
#                 print j+1
                ans.append(j+1)
                flag = 1
                break
        if flag==0:
#             print -1
            ans.append(-1)

for i in range(int(m)):
    print ans[i]
#         flag=1
#     if flag==0:print l[int(r[0])-1:int(r[1])].index(int(r[2]))+1


#-*- coding: UTF-8 -*-
'''
Created on 2016year 5month 4day

@author: yuhaomin
'''

lflag = []
n,m= raw_input().split(' ')
l = raw_input().split(' ')
l = [int(index) for index in l]
x=range(int(n))

lflag.append(0)

for i in x[1:]:
    if l[i] == l[i-1]:
        lflag.append(lflag[i-1])
    else:
        lflag.append(i)
# print lflag
r=[]
ans=[]

for i in range(int(m)):
    r = raw_input().split(' ')
    r = [int(index) for index in r]
    flag = 0
    j = r[1]-1
    while(1):
        if j < r[0] - 1:
            break
        if l[j] != r[2]:
            print j+1
            flag = 1
            break
        j = lflag[j] - 1
    if flag == 0:
        print -1


#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;
const int N = 200005;
# define PI 3.141592657

bool cmp(int x, int y){
	return x>y;
}
//struct node{ int x; int y;}a[N];

int main()
{
	int n,m;
	int a[N];
	int po[N];
	cin>>n>>m;
	//cin >> a[0];
	//po[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		cin>>a[i];
		if (i == 1)
		{
			po[i] = -1;
		}else
		{
			if (a[i] == a[i-1])
			{
				po[i] = po[i-1];
			}else
			{
				po[i] = i-1;
			}
		}

		//cout<<po[i]<<" ";
	}

	int l,r,x;

	for (int i = 0; i < m; i++)
	{
		cin >> l >> r >> x;
		if (a[r] == x)
		{
			if (po[r]< l)
			{
				cout<<"-1"<<endl;
			}else
			{
				cout<<po[r]<<endl;
			}
		}else
		{
			cout<<r<<endl;
		}
	}
	cin>>n;
	return 0;
}


#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;
const int N = 20005;
# define PI 3.141592657

bool cmp(int x, int y){
	return x>y;
}
//struct node{ int x; int y;}a[N];

int main()
{
	int n,m;
	int a[N];
	int po[N];
	cin>>n>>m;
	cin >> a[0];
	po[0] = 0;
	for (int i = 1; i < n; i++)
	{
		cin>>a[i];
		if (a[i] == a[i-1])
		{
			po[i] = po[i-1];
		}else
		{
			po[i] = i;
		}
		//cout<<po[i]<<" ";
	}

	int l,r,x;

	for (int i = 0; i < m; i++)
	{
		cin >> l >> r >> x;
		int flag = 0;
		for (int j = r-1; j > l-1;)
		{
			if (a[j]!=x)
			{
				cout<<j+1<<endl;
				flag=1;
				break;
			}
			j = po[j] - 1;
		}
		if (flag==0)
		{
			cout<<-1<<endl;
		}
	}
	return 0;
}


#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;
const int N = 1000010;
# define PI 3.141592657

bool cmp(int x, int y){
	return x>y;
}
//struct node{ int x; int y;}a[N];

int main()
{
	int n,m;
	int a[N];
	int po[N];
	scanf("%d%d",&n,&m);
	//cin >> a[0];
	//po[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d",&a[i]);
		if (i == 1)
		{
			po[i] = -1;
		}else
		{
			if (a[i] == a[i-1])
			{
				po[i] = po[i-1];
			}else
			{
				po[i] = i-1;
			}
		}

		//cout<<po[i]<<" ";
	}

	int l,r,x;

	while(m--)
	{
		scanf("%d%d%d",&l,&r,&x);
		if (a[r] == x)
		{
			if (po[r]< l)
			{
				printf("%d\n",-1);
			}else
			{
				printf("%d\n",po[r]);
			}
		}else
		{
			printf("%d\n",r);
		}
	}
	cin>>n;
	return 0;
}


#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;
const int N = 200005;
# define PI 3.141592657

bool cmp(int x, int y){
	return x>y;
}
//struct node{ int x; int y;}a[N];

int main()
{
	int n,m;
	int a[N];
	int po[N];
	scanf("%d%d",&n,&m);
	//cin >> a[0];
	//po[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d",&a[i]);
		if (i == 1)
		{
			po[i] = -1;
		}else
		{
			if (a[i] == a[i-1])
			{
				po[i] = po[i-1];
			}else
			{
				po[i] = i-1;
			}
		}

		//cout<<po[i]<<" ";
	}

	int l,r,x;

	while(m--)
	{
		scanf("%d%d%d",&l,&m,&x);
		if (a[r] == x)
		{
			if (po[r]< l)
			{
				printf("%d",-1);
			}else
			{
				printf("%d",po[r]);
			}
		}else
		{
			printf("%d",r);
		}
	}
	cin>>n;
	return 0;
}


#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;
const int N = 200005;
# define PI 3.141592657

bool cmp(int x, int y){
	return x>y;
}
//struct node{ int x; int y;}a[N];

int main()
{
	int n,m;
	int a[N];
	int po[N];
	cin>>n>>m;
	cin >> a[0];
	po[0] = 0;
	for (int i = 1; i < n; i++)
	{
		cin>>a[i];
		if (a[i] == a[i-1])
		{
			po[i] = po[i-1];
		}else
		{
			po[i] = i;
		}
		//cout<<po[i]<<" ";
	}

	int l,r,x;

	for (int i = 0; i < m; i++)
	{
		cin >> l >> r >> x;
		int flag = 0;
		for (int j = r-1; j >=
			l-1;)
		{
			if (a[j]!=x)
			{
				cout<<j+1<<endl;
				flag=1;
				break;
			}
			j = po[j] - 1;
		}
		if (flag==0)
		{
			cout<<-1<<endl;
		}
	}
	cin>>n;
	return 0;
}


#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;
const int N = 20005;
# define PI 3.141592657

bool cmp(int x, int y){
	return x>y;
}
//struct node{ int x; int y;}a[N];

int main()
{
	int n,m;
	int a[N];
	int po[N];
	scanf("%d%d",&n,&m);
	scanf("%d",&a[0]);
	po[0] = 0;
	for (int i = 1; i < n; i++)
	{
		scanf("%d",&a[i]);
		if (a[i] == a[i-1])
		{
			po[i] = po[i-1];
		}else
		{
			po[i] = i;
		}
		//cout<<po[i]<<" ";
	}

	int l,r,x;

	for (int i = 0; i < m; i++)
	{
		scanf("%d%d%d",&l,&r,&x);
		int flag = 0;
		for (int j = r-1; j >=l-1;)
		{
			if (a[j]!=x)
			{
				printf("%d\n",j+1);
				flag=1;
				break;
			}
			j = po[j] - 1;
		}
		if (flag==0)
		{
			printf("%d\n",-1);
		}
	}
	cin>>n;
	return 0;
}


#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;
const int N = 1000005;
# define PI 3.141592657

bool cmp(int x, int y){
	return x>y;
}
//struct node{ int x; int y;}a[N];

int main()
{
	int n,m;
	int a[N];
	int po[N];
	scanf("%d%d",&n,&m);
	scanf("%d",&a[0]);
	po[0] = 0;
	for (int i = 1; i < n; i++)
	{
		scanf("%d",&a[i]);
		if (a[i] == a[i-1])
		{
			po[i] = po[i-1];
		}else
		{
			po[i] = i;
		}
		//cout<<po[i]<<" ";
	}

	int l,r,x;

	for (int i = 0; i < m; i++)
	{
		scanf("%d",&l,&r,&x);
		int flag = 0;
		for (int j = r-1; j >=
			l-1;)
		{
			if (a[j]!=x)
			{
				printf("%d\n",j+1);
				flag=1;
				break;
			}
			j = po[j] - 1;
		}
		if (flag==0)
		{
			printf("%d\n",-1);
		}
	}
	return 0;
}


#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;
const int N = 1000005;
# define PI 3.141592657

bool cmp(int x, int y){
	return x>y;
}
//struct node{ int x; int y;}a[N];

int main()
{
	int n,m;
	int a[N];
	int po[N];
	scanf("%d%d",&n,&m);
	scanf("%d",&a[0]);
	po[0] = 0;
	for (int i = 1; i < n; i++)
	{
		scanf("%d",&a[i]);
		if (a[i] == a[i-1])
		{
			po[i] = po[i-1];
		}else
		{
			po[i] = i;
		}
		//cout<<po[i]<<" ";
	}

	int l,r,x;

	for (int i = 0; i < m; i++)
	{
		scanf("%d%d%d",&l,&r,&x);
		int flag = 0;
		for (int j = r-1; j >=l-1;)
		{
			if (a[j]!=x)
			{
				printf("%d\n",j+1);
				flag=1;
				break;
			}
			j = po[j] - 1;
		}
		if (flag==0)
		{
			printf("%d\n",-1);
		}
	}
	cin>>n;
	return 0;
}


#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;
const int N = 20005;
# define PI 3.141592657

bool cmp(int x, int y){
	return x>y;
}
//struct node{ int x; int y;}a[N];

int main()
{
	int n,m;
	int a[N];
	int po[N];
	cin>>n>>m;
	//cin >> a[0];
	//po[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		cin>>a[i];
		if (i == 1)
		{
			po[i] = -1;
		}else
		{
			if (a[i] == a[i-1])
			{
				po[i] = po[i-1];
			}else
			{
				po[i] = i-1;
			}
		}

		//cout<<po[i]<<" ";
	}

	int l,r,x;

	for (int i = 0; i < m; i++)
	{
		cin >> l >> r >> x;
		if (a[r] == x)
		{
			if (po[r]< l)
			{
				cout<<"-1"<<endl;
			}else
			{
				cout<<po[r]<<endl;
			}
		}else
		{
			cout<<r<<endl;
		}
	}
	cin>>n;
	return 0;
}


#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;
const int N = 200010;
# define PI 3.141592657

bool cmp(int x, int y){
	return x>y;
}
//struct node{ int x; int y;}a[N];

int main()
{
	int n,m;
	int a[N];
	int po[N];
	scanf("%d%d",&n,&m);
	//cin >> a[0];
	//po[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d",&a[i]);
		if (i == 1)
		{
			po[i] = -1;
		}else
		{
			if (a[i] == a[i-1])
			{
				po[i] = po[i-1];
			}else
			{
				po[i] = i-1;
			}
		}

		//cout<<po[i]<<" ";
	}

	int l,r,x;

	while(m--)
	{
		scanf("%d%d%d",&l,&r,&x);
		if (a[r] == x)
		{
			if (po[r]< l)
			{
				printf("%d\n",-1);
			}else
			{
				printf("%d\n",po[r]);
			}
		}else
		{
			printf("%d",r);
		}
	}
	cin>>n;
	return 0;
}


#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;
const int N = 20005;
# define PI 3.141592657

bool cmp(int x, int y){
	return x>y;
}
//struct node{ int x; int y;}a[N];

int main()
{
	int n,m;
	int a[N];
	int po[N];
	cin>>n>>m;
	cin >> a[0];
	po[0] = 0;
	for (int i = 1; i < n; i++)
	{
		cin>>a[i];
		if (a[i] == a[i-1])
		{
			po[i] = po[i-1];
		}else
		{
			po[i] = i;
		}
		//cout<<po[i]<<" ";
	}

	int l,r,x;

	for (int i = 0; i < m; i++)
	{
		cin >> l >> r >> x;
		int flag = 0;
		for (int j = r-1; j >=
			l-1;)
		{
			if (a[j]!=x)
			{
				cout<<j+1<<endl;
				flag=1;
				break;
			}
			j = po[j] - 1;
		}
		if (flag==0)
		{
			cout<<-1<<endl;
		}
	}
	cin>>n;
	return 0;
}


//#define Testing

//#define FileIO

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <time.h>
#include <bitset>
#include <functional>

using namespace std;

#define ABS(a) ((a<0)?-(a):a)
#define MIN(a, b) ((a<b)?a:b)
#define MAX(a, b) ((a>b)?a:b)
#define FOR(i,a,n) for ( int i = (a); i < (n); ++i)
#define FORI(s, n) for(LL i=s; i<n; i++)
#define mp(a, b) make_pair(a, b)
typedef long long LL;

double eps = 0.00000001;
const LL INF = 1000000009;
const LL MAXNUM = 10004;
const LL MOD = 1000000007;

LL poww(LL v, LL p)
{
	if (p == 0) return 1;

	if (p & 1)
	{
		return (poww(v, p - 1) * v) % MOD;
	}
	else
	{
		LL t = poww(v, p / 2);
		return (t * t) % MOD;
	}
}

string s1, s2;
LL res = 0;

int n, m;
vector<int> V;
vector<int> R;

int main()
{
#ifdef FileIO
	freopen("COME_HERE.txt", "r", stdin);
	freopen("GO_AWAY.txt", "w", stdout);
#endif // FileIO
#ifdef Testing
	clock_t Start = clock();
#endif // Testing
	//----------------------------------------

	cin >> n >> m;
	int a = 0;
	V.push_back(a);
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		V.push_back(a);
	}

	R.resize(n + 5);
	R[1] = -1;
	for (int i = 2; i <= n; i++)
	{
		if (V[i] != V[i-1]) R[i] = i-1;
		else R[i] = R[i-1];
	}

	int l, r, x;
	for (int i = 0; i < m; i++)
	{
		cin >> l >> r >> x;
		if (V[r] != x) cout << r << endl;
		else if (R[r] >= l) cout << R[r] << endl;
		else cout << -1 << endl;
	}

	//----------------------------------------
#ifdef Testing
	cout << "\nTime: " << clock() - Start << endl;
#endif // Testing

	return 0;
}


//#define Testing

//#define FileIO

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <time.h>
#include <bitset>
#include <functional>

using namespace std;

#define ABS(a) ((a<0)?-(a):a)
#define MIN(a, b) ((a<b)?a:b)
#define MAX(a, b) ((a>b)?a:b)
#define FOR(i,a,n) for ( int i = (a); i < (n); ++i)
#define FORI(s, n) for(LL i=s; i<n; i++)
#define mp(a, b) make_pair(a, b)
typedef long long LL;

double eps = 0.00000001;
const LL INF = 1000000009;
const LL MAXNUM = 10004;
const LL MOD = 1000000007;

LL poww(LL v, LL p)
{
	if (p == 0) return 1;

	if (p & 1)
	{
		return (poww(v, p - 1) * v) % MOD;
	}
	else
	{
		LL t = poww(v, p / 2);
		return (t * t) % MOD;
	}
}

string s1, s2;
LL res = 0;

int n, m;
vector<int> V;

int main()
{
#ifdef FileIO
	freopen("COME_HERE.txt", "r", stdin);
	freopen("GO_AWAY.txt", "w", stdout);
#endif // FileIO
#ifdef Testing
	clock_t Start = clock();
#endif // Testing
	//----------------------------------------

	cin >> n >> m;
	int a = 0;
	V.push_back(a);
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		V.push_back(a);
	}

	int l, r, x;
	for (int i = 0; i < m; i++)
	{
		res = -1;
		cin >> l >> r >> x;
		for (int j = l; j <= r; j++)
		{
			if (V[j] != x)
			{
				res = j;
				break;
			}
		}
		cout << res << endl;
	}

	//----------------------------------------
#ifdef Testing
	cout << "\nTime: " << clock() - Start << endl;
#endif // Testing

	return 0;
}


//#define Testing

//#define FileIO

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <time.h>
#include <bitset>
#include <functional>

using namespace std;

#define ABS(a) ((a<0)?-(a):a)
#define MIN(a, b) ((a<b)?a:b)
#define MAX(a, b) ((a>b)?a:b)
#define FOR(i,a,n) for ( int i = (a); i < (n); ++i)
#define FORI(s, n) for(LL i=s; i<n; i++)
#define mp(a, b) make_pair(a, b)
typedef long long LL;

double eps = 0.00000001;
const LL INF = 1000000009;
const LL MAXNUM = 10004;
const LL MOD = 1000000007;

LL poww(LL v, LL p)
{
	if (p == 0) return 1;

	if (p & 1)
	{
		return (poww(v, p - 1) * v) % MOD;
	}
	else
	{
		LL t = poww(v, p / 2);
		return (t * t) % MOD;
	}
}

string s1, s2;
LL res = 0;

int n, m;
vector<int> V;
vector<int> R;

int main()
{
#ifdef FileIO
	freopen("COME_HERE.txt", "r", stdin);
	freopen("GO_AWAY.txt", "w", stdout);
#endif // FileIO
#ifdef Testing
	clock_t Start = clock();
#endif // Testing
	//----------------------------------------

	cin >> n >> m;
	int a = 0;
	V.push_back(a);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a);
		V.push_back(a);
	}

	R.resize(n + 5);
	R[1] = -1;
	for (int i = 2; i <= n; i++)
	{
		if (V[i] != V[i-1]) R[i] = i-1;
		else R[i] = R[i-1];
	}

	int l, r, x;
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d%d", &l, &r, &x);
		if (V[r] != x) cout << r << endl;
		else if (R[r] >= l) cout << R[r] << endl;
		else cout << -1 << endl;
	}

	//----------------------------------------
#ifdef Testing
	cout << "\nTime: " << clock() - Start << endl;
#endif // Testing

	return 0;
}


#include <iostream>
using namespace std;
#define N 200100
int a[N], pre[N];
int n, m;
void input()
{
	int i;
	for (i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
}
void solve()
{
	int i;
	pre[0] = -1;
	for (i = 2; i <= n; i++) {
		if (a[i] != a[i - 1]) {
			pre[i] = i - 1;
		}
		else {
			pre[i] = pre[i - 1];
		}
	}
	int l, r, x;
	for (i = 0; i < m; i++) {
		scanf("%d %d %d", &l, &r, &x);
		if (a[r] != x) {
			printf("%d\n", r);
		}
		else {
			r = pre[r];
			if (r >= l) {
				printf("%d\n", r);
			}
			else {
				printf("-1\n");
			}
		}
	}
}
int main()
{
	while (scanf("%d %d", &n, &m) != EOF) {
		input();
		solve();
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1e6 + 200;
int a[maxn], l[maxn], r[maxn],n,m,ans[maxn];
int main()
{
	scanf("%d%d", &n, &m);
	l[1] = -maxn; r[n] = maxn;
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for (int i = 2; i <= n; i++)
		if (a[i] == a[i - 1])l[i] = l[i - 1];
		else l[i] = i - 1;
	for (int i = n - 1; i > 0; i--)
		if (a[i] == a[i + 1])r[i] = r[i + 1];
		else r[i] = i + 1;
		int ll, rr,p;
		while (m--)
		{
			scanf("%d%d%d", &ll, &rr,&p);
			if (l[p] >= ll&&l[p]<=rr)printf("%d\n", l[p]);
			else if (r[p] <= rr&&r[p]>=ll)printf("%d\n", r[p]);
			else printf("-1\n");
		}
		return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1e6 + 200;
int a[maxn],r[maxn],n,m;
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	r[n] = n + 1;
	for (int i = n - 1; i > 0; i--)
		if (a[i] == a[i + 1])r[i] = r[i + 1];
		else r[i] = i + 1;
	int ll, rr,x;
	while (m--)
	{
		scanf("%d%d%d", &ll, &rr,&x);
		if (a[ll] != x)printf("%d\n", ll);
		else if (r[ll] > rr)printf("-1\n");
		else printf("%d\n", r[ll]);
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;

struct node {
	int k;
	int p;
};

struct line {
	int k;
	int l;
	int r;
};

bool comp( line a, line b ) {
	if( a.k < b.k ) {
		return true;
	}
	if( a.k > b.k ) {
		return false;
	}
	return a.l < b.l;
}

int findLeft( vector<line> &b, int x ) {
	int l = 0; int r = b.size() - 1;
	int suc = -1;
	while( r - l >= 0 ) {
		int m = (l+r)/2;
		if( b[m].k < x ) {
			suc = m;
			l = m + 1;
		} else {
			r = m-1;
		}
	}
	return suc;
}

int findRight( vector<line> &b, int x ) {
	int l = 0; int r = b.size() - 1;
	int suc = b.size();
	while( r - l >= 0 ) {
		int m = (l+r)/2;
		if( b[m].k > x ) {
			suc = m;
			r = m - 1;
		} else {
			l = m + 1;
		}
	}
	return suc;
}

int findLine( vector<line> &b, int left, int right, int l_out ) {
	int l = left; int r = right;
	int suc = left - 1;
	while( r - l >= 0 ) {
		int m = (l+r)/2;
		if( b[m].l < l_out ) {
			suc = m;
			l = m + 1;
		} else {
			r = m - 1;
		}
	}
	return suc;
}

int countAns( vector<line> &b, int l, int r, int x ) {
	int left = findLeft(b,x) + 1;
	int right = findRight(b,x) - 1;
	if( left > right )
		return l;

	int N = findLine(b,left,right,l) + 1;
	if( b[N].r < l || b[N].l > r) {
		return l;
	} else {
		if( l >= b[N].l && r <= b[N].r ) {
			return -1;
		} else {
			if( l < b[N].l ) {
				return l;
			} else {
				return b[N].r + 1;
			}
		}
	}

};

int main()  {

	int n,m;
	cin >> n >> m;
	vector<node> a(n+1);
	for( int i = 0; i < n; i++ ) {
		cin >> a[i].k;
		a[i].p = i+1;
	}
	//stable_sort(a.begin(),a.end(),comp);

	vector<line> b;
	int s = 1;
	int cp = a[0].p;
	int ck = a[0].k;
	for( int i = 1; i < n; i++ ) {
		if( a[i].k == ck && a[i].p == cp + 1 ) {
			cp +=1;
		} else {
			line t;
			t.k = ck;
			t.l = s;
			t.r = cp;
			b.push_back(t);
			s = a[i].p;
			cp = s;
			ck = a[i].k;
		}
	}
	line t;
	t.k = ck;
	t.l = s;
	t.r = cp;
	b.push_back(t);

	stable_sort(b.begin(), b.end(), comp);

	for( int i = 0; i < m; i++ ) {
		int l, r, x;
		cin >> l >> r >> x;
		cout << countAns(b,l,r,x) << endl;
	}

    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;

struct node {
	int k;
	int p;
};

struct line {
	int k;
	int l;
	int r;
};

bool comp( line a, line b ) {
	if( a.k < b.k ) {
		return true;
	}
	if( a.k > b.k ) {
		return false;
	}
	return a.l < b.l;
}

int findLeft( vector<line> &b, int x ) {
	int l = 0; int r = b.size() - 1;
	int suc = -1;
	while( r - l >= 0 ) {
		int m = (l+r)/2;
		if( b[m].k < x ) {
			suc = m;
			l = m + 1;
		} else {
			r = m-1;
		}
	}
	return suc;
}

int findRight( vector<line> &b, int x ) {
	int l = 0; int r = b.size() - 1;
	int suc = b.size();
	while( r - l >= 0 ) {
		int m = (l+r)/2;
		if( b[m].k > x ) {
			suc = m;
			r = m - 1;
		} else {
			l = m + 1;
		}
	}
	return suc;
}

int findLine( vector<line> &b, int left, int right, int l_out ) {
	int l = left; int r = right;
	int suc = left - 1;
	while( r - l >= 0 ) {
		int m = (l+r)/2;
		if( b[m].l < l_out ) {
			suc = m;
			l = m + 1;
		} else {
			r = m - 1;
		}
	}
	return suc;
}

int countAns( vector<line> &b, int l, int r, int x ) {
	int left = findLeft(b,x) + 1;
	int right = findRight(b,x) - 1;
	if( left > right )
		return l;

	int N = findLine(b,left,right,l) + 1;
	if( b[N].k != x )
		return l;
	if( b[N].r < l || b[N].l > r) {
		return l;
	} else {
		if( l >= b[N].l && r <= b[N].r ) {
			return -1;
		} else {
			if( l < b[N].l ) {
				return l;
			} else {
				return b[N].r + 1;
			}
		}
	}

};

int main()  {

	int n,m;
	cin >> n >> m;
	vector<node> a(n+1);
	for( int i = 0; i < n; i++ ) {
		cin >> a[i].k;
		a[i].p = i+1;
	}
	//stable_sort(a.begin(),a.end(),comp);

	vector<line> b;
	int s = 1;
	int cp = a[0].p;
	int ck = a[0].k;
	for( int i = 1; i < n; i++ ) {
		if( a[i].k == ck && a[i].p == cp + 1 ) {
			cp +=1;
		} else {
			line t;
			t.k = ck;
			t.l = s;
			t.r = cp;
			b.push_back(t);
			s = a[i].p;
			cp = s;
			ck = a[i].k;
		}
	}
	line t;
	t.k = ck;
	t.l = s;
	t.r = cp;
	b.push_back(t);

	stable_sort(b.begin(), b.end(), comp);

	for( int i = 0; i < m; i++ ) {
		int l, r, x;
		cin >> l >> r >> x;
		cout << countAns(b,l,r,x) << endl;
	}

    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;

struct node {
	int k;
	int p;
};

struct line {
	int k;
	int l;
	int r;
};

bool comp( line a, line b ) {
	if( a.k < b.k ) {
		return true;
	}
	if( a.k > b.k ) {
		return false;
	}
	return a.l < b.l;
}

int findLeft( vector<line> &b, int x ) {
	int l = 0; int r = b.size() - 1;
	int suc = -1;
	while( r - l >= 0 ) {
		int m = (l+r)/2;
		if( b[m].k < x ) {
			suc = m;
			l = m + 1;
		} else {
			r = m-1;
		}
	}
	return suc;
}

int findRight( vector<line> &b, int x ) {
	int l = 0; int r = b.size() - 1;
	int suc = b.size();
	while( r - l >= 0 ) {
		int m = (l+r)/2;
		if( b[m].k > x ) {
			suc = m;
			r = m - 1;
		} else {
			l = m + 1;
		}
	}
	return suc;
}

int findLine( vector<line> &b, int left, int right, int l_out ) {
	int l = left; int r = right;
	int suc = left - 1;
	while( r - l >= 0 ) {
		int m = (l+r)/2;
		if( b[m].r < l_out ) {
			suc = m;
			l = m + 1;
		} else {
			r = m - 1;
		}
	}
	return suc;
}

int countAns( vector<line> &b, int l, int r, int x ) {
	if( x > b[b.size()-1].k && x < b[0].k )
		return l;
	int left = findLeft(b,x) + 1;
	int right = findRight(b,x) - 1;
	if( left > right )
		return l;

	int N = findLine(b,left,right,l) + 1;
	if( b[N].k != x )
		return l;
	if( b[N].r < l || b[N].l > r) {
		return l;
	} else {
		if( l >= b[N].l && r <= b[N].r ) {
			return -1;
		} else {
			if( l < b[N].l ) {
				return l;
			} else {
				return b[N].r + 1;
			}
		}
	}

};

int main()  {

	int n,m;
	cin >> n >> m;
	vector<node> a(n+1);
	for( int i = 0; i < n; i++ ) {
		cin >> a[i].k;
		a[i].p = i+1;
	}
	//stable_sort(a.begin(),a.end(),comp);

	vector<line> b;
	int s = 1;
	int cp = a[0].p;
	int ck = a[0].k;
	for( int i = 1; i < n; i++ ) {
		if( a[i].k == ck && a[i].p == cp + 1 ) {
			cp +=1;
		} else {
			line t;
			t.k = ck;
			t.l = s;
			t.r = cp;
			b.push_back(t);
			s = a[i].p;
			cp = s;
			ck = a[i].k;
		}
	}
	line t;
	t.k = ck;
	t.l = s;
	t.r = cp;
	b.push_back(t);

	stable_sort(b.begin(), b.end(), comp);

	for( int i = 0; i < m; i++ ) {
		int l, r, x;
		cin >> l >> r >> x;
		cout << countAns(b,l,r,x) << endl;
	}

    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;

struct node {
	int k;
	int p;
};

struct line {
	int k;
	int l;
	int r;
};

bool comp( line a, line b ) {
	if( a.k < b.k ) {
		return true;
	}
	if( a.k > b.k ) {
		return false;
	}
	return a.l < b.l;
}

int findLeft( vector<line> &b, int x ) {
	int l = 0; int r = b.size() - 1;
	int suc = -1;
	while( r - l >= 0 ) {
		int m = (l+r)/2;
		if( b[m].k < x ) {
			suc = m;
			l = m + 1;
		} else {
			r = m-1;
		}
	}
	return suc;
}

int findRight( vector<line> &b, int x ) {
	int l = 0; int r = b.size() - 1;
	int suc = b.size();
	while( r - l >= 0 ) {
		int m = (l+r)/2;
		if( b[m].k > x ) {
			suc = m;
			r = m - 1;
		} else {
			l = m + 1;
		}
	}
	return suc;
}

int findLine( vector<line> &b, int left, int right, int l_out ) {
	int l = left; int r = right;
	int suc = left - 1;
	while( r - l >= 0 ) {
		int m = (l+r)/2;
		if( b[m].r < l_out ) {
			suc = m;
			l = m + 1;
		} else {
			r = m - 1;
		}
	}
	return suc;
}

int countAns( vector<line> &b, int l, int r, int x ) {
	if( x > b[b.size()-1].k && x < b[0].k )
		return l;
	int left = findLeft(b,x) + 1;
	int right = findRight(b,x) - 1;
	if( left > right )
		return l;

	int N = findLine(b,left,right,l) + 1;
	if( b[N].k != x )
		return l;
	if( b[N].r < l || b[N].l > r) {
		return l;
	} else {
		if( l >= b[N].l && r <= b[N].r ) {
			return -1;
		} else {
			if( l < b[N].l ) {
				return l;
			} else {
				return b[N].r + 1;
			}
		}
	}

};

int main()  {

	int n,m;
	cin >> n >> m;
	vector<node> a(n+1);
	for( int i = 0; i < n; i++ ) {
		scanf("%d",&a[i].k);
		a[i].p = i+1;
	}

	vector<line> b;
	int s = 1;
	int cp = a[0].p;
	int ck = a[0].k;
	for( int i = 1; i < n; i++ ) {
		if( a[i].k == ck && a[i].p == cp + 1 ) {
			cp +=1;
		} else {
			line t;
			t.k = ck;
			t.l = s;
			t.r = cp;
			b.push_back(t);
			s = a[i].p;
			cp = s;
			ck = a[i].k;
		}
	}
	line t;
	t.k = ck;
	t.l = s;
	t.r = cp;
	b.push_back(t);

	stable_sort(b.begin(), b.end(), comp);

	for( int i = 0; i < m; i++ ) {
		int l, r, x;
		scanf("%d %d %d",&l,&r,&x);
		printf("%d\n",countAns(b,l,r,x));
	}

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

#define max(a, b) a > b ? a : b
#define min(a, b) a < b > a : b

int n, m, l, r, x, a[200005], p[200005];

int main() {

	cin >> n >> m;
	for (int i = 1; i <= n; ++i){
		cin >> a[i];
		 (a[i] == a[i - 1]) ? p[i] = p[i - 1] : p[i] = i;
	}

	for (int i = 1; i <= m; ++i){
		cin >> l >> r >> x;

		int idx = -1;
		for (int j = r; j >= l; --j){
			if (a[j] != x){
				idx = j ; break;
			}
			else{
				j = p[j];
			}
		}

		cout << idx << endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

#define max(a, b) a > b ? a : b
#define min(a, b) a < b > a : b

int a[1000000];

int main() {

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

	int l, r, x;
	for (int i = 0; i < m; ++i){
		cin >> l >> r >> x;
		bool f = 0;
		int j;
		for (j = l; i <= r; ++j){
			if (x != a[j]) f = 1;
			break;
		}

		if (f){
			cout << a[j];
		}
		else{
			cout << -1;
		}

		cout << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

#define max(a, b) a > b ? a : b
#define min(a, b) a < b > a : b

int a[1000000];

int main() {

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

	int l, r, x;
	for (int i = 0; i < m; ++i){
		cin >> l >> r >> x;
		bool f = 0;
		int pos = -1;

		for (int j = l; j <= r; ++j){
			if (x != a[j - 1]) pos = j;
		}

		cout << pos <<endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

#define max(a, b) a > b ? a : b
#define min(a, b) a < b > a : b

int a[1000000];

int main() {

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

	int l, r, x;
	for (int i = 0; i < m; ++i){
		cin >> l >> r >> x;
		bool f = 0;
		int j;
		for (j = l; i <= r; ++j){
			if (x != a[j]) f = 1;
			break;
		}

		if (f){
			cout << j;
		}
		else{
			cout << -1;
		}

		cout << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

#define max(a, b) a > b ? a : b
#define min(a, b) a < b > a : b

int n, m, l, r, x, a[200005], p[200005];

int main() {

	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i){
		scanf("%d", &a[i]);
		 (a[i] == a[i - 1]) ? p[i] = p[i - 1] : p[i] = i - 1;
	}

	for (int i = 1; i <= m; ++i){
		scanf("%d %d %d", &l, &r, &x);

		printf("%d\n", ((a[r] == x) ? p[r] >= l ? p[r] : -1 : r));
	}

	scanf("\n");

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

#define max(a, b) a > b ? a : b
#define min(a, b) a < b > a : b

int a[1000000];

int main() {

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

	int l, r, x;
	for (int i = 0; i < m; ++i){
		cin >> l >> r >> x;
		bool f = 0;
		int pos = -1;

		for (int j = r; j >=l; --j){
			if (x != a[j - 1]) { pos = j; break; };
		}

		cout << pos <<endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

#define max(a, b) a > b ? a : b
#define min(a, b) a < b > a : b

int n, m, l, r, x, a[200005], p[200005];

int main() {

	cin >> n >> m;
	for (int i = 1; i <= n; ++i){
		cin >> a[i];
		 (a[i] == a[i - 1]) ? p[i] = p[i - 1] : p[i] = i - 1;
	}

	for (int i = 1; i <= m; ++i){
		cin >> l >> r >> x;

		cout << ((a[r] == x) ? p[r] >= l ? p[r] : -1 : r) << endl;;
	}

	return 0;
}


#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <map>
#include <time.h>
#include <string>
#include <algorithm>
#include <queue>
#include <assert.h>
#include <math.h>
#include <iostream>
using namespace std;

int n,m;
int s[1900005];
int a[200005];

void build(int v, int l, int r) {
	if (l == r) {
		s[v] = -1;
		return;
	}

	int m = (l + r) / 2;
	build(2 * v, l, m);
	build(2 * v + 1, m + 1, r);
	if (s[2 * v] != -1)
		s[v] = s[2 * v];
	else {
	    if (s[2*v+1==-1]) {
	        if (a[l]!=a[m+1])
	            s[v]=m+1;
	        else
	            s[v]=-1;
	    } else {
	        if (a[l]!=a[m+1])
	            s[v]=m+1;
	        else
	            s[v]=s[2*v+1];
	    }

	}
}

int find(int v, int l, int r, int x, int y) {
	if (l == x && r == y) {
		return s[v];
	}

		int m = (l + r) / 2;
		if (y <= m)
		    return find(2 * v, l, m, x, y);
		if (x > m)
			return find(2 * v + 1, m + 1, r, x, y);

		int g=find(2 * v, l, m, x, m);
		int j=find(2 * v + 1, m+1, r, m+1, y);

		if (g != -1)
			return g;
		else {
			if (j != -1) {
				if (a[x]!=a[m+1])
				    return m+1;
				else
				    return j;
			} else {
			    if (a[x]==a[m+1])
			        return -1;
			    else
			        return m+1;

			}

		}

}

int main() {
#pragma warning(disable : 4996)
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d%d", &n,&m);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	build(1, 1, n );

	for (int i = 0; i < m; i++) {
		int h, b, x;
		scanf("%d%d%d", &h, &b, &x);
		if (x!=a[h])
		    printf("%d\n",h);
		else
		    printf("%d\n",find(1,1,n,h,b));
	}

	return 0;
}


#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <map>
#include <time.h>
#include <string>
#include <algorithm>
#include <queue>
#include <assert.h>
#include <math.h>
#include <iostream>
using namespace std;

int n,m;
int s[600005];
int a[200005];

void build(int v, int l, int r) {
	if (l == r) {
		s[v] = -1;
		return;
	}

	int m = (l + r) / 2;
	build(2 * v, l, m);
	build(2 * v + 1, m + 1, r);
	if (s[2 * v] != -1)
		s[v] = s[2 * v];
	else {
	    if (s[2*v+1==-1]) {
	        if (a[l]!=a[m+1])
	            s[v]=m+1;
	        else
	            s[v]=-1;
	    } else {
	        if (a[l]!=a[m+1])
	            s[v]=m+1;
	        else
	            s[v]=s[2*v+1];
	    }

	}
}

int find(int v, int l, int r, int x, int y) {
	if (l == x && r == y) {
		return s[v];
	}

		int m = (l + r) / 2;
		if (y <= m)
		    return find(2 * v, l, m, x, y);
		if (x > m)
			return find(2 * v + 1, m + 1, r, x, y);

		if (find(2 * v, l, m, x, m) != -1)
			return find(2 * v, l, m, x, m);
		else {
			if (find(2 * v + 1, m+1, r, m+1, y) != -1) {
				if (a[x]!=a[m+1])
				    return m+1;
				else
				    return find(2 * v + 1, m+1, r, m+1, y);
			} else {
			    if (a[x]==a[m+1])
			        return -1;
			    else
			        return m+1;

			}

		}

}

int main() {
#pragma warning(disable : 4996)
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d%d", &n,&m);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	build(1, 1, n );

	for (int i = 0; i < m; i++) {
		int h, b, x;
		scanf("%d%d%d", &h, &b, &x);
		if (x!=a[h])
		    printf("%d\n",h);
		else
		    printf("%d\n",find(1,1,n,h,b));
	}

	//for (int i = 1; i <= 10; i++)
		//cout << s[i] << endl;

	return 0;
}


#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <map>
#include <time.h>
#include <string>
#include <algorithm>
#include <queue>
#include <assert.h>
#include <math.h>
#include <iostream>
using namespace std;

int n,m;
int s[1900005];
int a[200005];

void build(int v, int l, int r) {
	if (l == r) {
		s[v] = -1;
		return;
	}

	int m = (l + r) / 2;
	build(2 * v, l, m);
	build(2 * v + 1, m + 1, r);
	if (s[2 * v] != -1)
		s[v] = s[2 * v];
	else {
	    if (s[2*v+1==-1]) {
	        if (a[l]!=a[m+1])
	            s[v]=m+1;
	        else
	            s[v]=-1;
	    } else {
	        if (a[l]!=a[m+1])
	            s[v]=m+1;
	        else
	            s[v]=s[2*v+1];
	    }

	}
}

int find(int v, int l, int r, int x, int y) {
	if (l == x && r == y) {
		return s[v];
	}

		int m = (l + r) / 2;
		if (y <= m)
		    return find(2 * v, l, m, x, y);
		if (x > m)
			return find(2 * v + 1, m + 1, r, x, y);

		if (find(2 * v, l, m, x, m) != -1)
			return find(2 * v, l, m, x, m);
		else {
			if (find(2 * v + 1, m+1, r, m+1, y) != -1) {
				if (a[x]!=a[m+1])
				    return m+1;
				else
				    return find(2 * v + 1, m+1, r, m+1, y);
			} else {
			    if (a[x]==a[m+1])
			        return -1;
			    else
			        return m+1;

			}

		}

}

int main() {
#pragma warning(disable : 4996)
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d%d", &n,&m);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	build(1, 1, n );

	for (int i = 0; i < m; i++) {
		int h, b, x;
		scanf("%d%d%d", &h, &b, &x);
		if (x!=a[h])
		    printf("%d\n",h);
		else
		    printf("%d\n",find(1,1,n,h,b));
	}

	//for (int i = 1; i <= 10; i++)
		//cout << s[i] << endl;

	return 0;
}


# include <functional>
# include <algorithm>
# include <iostream>
//# include <hash_set>
//# include <hash_map>
# include <string.h>
# include <iterator>
# include <assert.h>
# include <utility>
# include <cstring>
# include <sstream>
# include <iomanip>
# include <bitset>
# include <string>
# include <cstdio>
# include <vector>
# include <deque>
# include <queue>
# include <stack>
# include <cmath>
# include <ctime>
# include <list>
# include <map>
# include <set>
//#pragma comment (linker, "/STACK:17000000")

#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef pair<int, int > P;
typedef long double db;

const db eps=1e-9, pi=acos(-1.0);
const ll inf=2000000009;

int n, m;
int l, r, x;
vector<int > a, z;

void solve(){
	scanf("%d%d", &n, &m);
	a.resize(n+1);
	z.resize(n+1);
	for(int i=1; i<=n; i++)
		scanf("%d", &a[i]);
	z[0]=-1;
	for(int i=1; i<=n; i++)
		if(a[i]!=a[i-1])
			z[i]=i-1;
		else
			z[i]=z[i-1];
	while(m--){
		scanf("%d%d%d", &l, &r, &x);
		if(a[r]!=x) printf("%d\n", r);
		else if(z[r]>=l) printf("%d\n", z[r]);
		else printf("-1\n");
	}
}

int main(){
//  freopen("INPUT.TXT", "r", stdin);   freopen("OUTPUT.TXT", "w", stdout);
    solve();
}
/*

*/


# include <functional>
# include <algorithm>
# include <iostream>
//# include <hash_set>
//# include <hash_map>
# include <string.h>
# include <iterator>
# include <assert.h>
# include <utility>
# include <cstring>
# include <sstream>
# include <iomanip>
# include <bitset>
# include <string>
# include <cstdio>
# include <vector>
# include <deque>
# include <queue>
# include <stack>
# include <cmath>
# include <ctime>
# include <list>
# include <map>
# include <set>
//#pragma comment (linker, "/STACK:17000000")

#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef pair<int, int > P;
typedef long double db;

const db eps=1e-9, pi=acos(-1.0);
const ll inf=2000000009;

int n, m;
int l, r, x;
vector<int > a, z;

void solve(){
	cin>>n>>m;
	a.resize(n+1);
	z.resize(n+1);
	for(int i=1; i<=n; i++)
		cin>>a[i];
	z[0]=-1;
	for(int i=1; i<=n; i++)
		if(a[i]!=a[i-1])
			z[i]=i-1;
		else
			z[i]=z[i-1];
	while(m--){
		cin>>l>>r>>x;
		if(a[r]!=x) cout<<r<<'\n';
		else if(z[r]>=l) cout<<z[r]<<'\n';
		else cout<<-1<<'\n';
	}
}

int main(){
//  freopen("INPUT.TXT", "r", stdin);   freopen("OUTPUT.TXT", "w", stdout);
    solve();
}
/*

*/


# include <functional>
# include <algorithm>
# include <iostream>
//# include <hash_set>
//# include <hash_map>
# include <string.h>
# include <iterator>
# include <assert.h>
# include <utility>
# include <cstring>
# include <sstream>
# include <iomanip>
# include <bitset>
# include <string>
# include <cstdio>
# include <vector>
# include <deque>
# include <queue>
# include <stack>
# include <cmath>
# include <ctime>
# include <list>
# include <map>
# include <set>
//#pragma comment (linker, "/STACK:17000000")

#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef pair<int, int > P;
typedef long double db;

const db eps=1e-9, pi=acos(-1.0);
const ll inf=2000000009;

int n, m;
int l, r, x;
vector<int > a, z;

void solve(){
	scanf("%d%d", &n, &m);
	a.resize(n+1);
	z.resize(n+1);
	for(int i=1; i<=n; i++)
		scanf("%d", &a[i]);
	z[0]=-1;
	for(int i=1; i<=n; i++)
		if(a[i]!=a[i-1])
			z[i]=i-1;
		else
			z[i]=z[i-1];
	while(m--){
		scanf("%d%d%d", &l, &r, &x);
		if(a[r]!=x) printf("%d\n", r);
		else if(z[r]>=l) printf("%d\n", z[r]);
		else printf("-1");
	}
}

int main(){
//  freopen("INPUT.TXT", "r", stdin);   freopen("OUTPUT.TXT", "w", stdout);
    solve();
}
/*

*/


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cstring>

using namespace std;

#define mp make_pair
#define pp push_back
#define Sort(x) sort(x.begin(), x.end())
#define rep(i, x, y) for(int i = x; i < y; ++i)
#define Rep(i, x, y) for(int i = x; i <= y; ++i)
#define dRep(i, x, y) for(int i = x;i >= y; --i)
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long
#define all(v) v.begin(),v.end()
#define ii pair<long long, long long>
#define mem(x, v) memset(x, v, sizeof(x))
#define nl '\n'
#define MOD 1000000007
#define readFile freopen("input.in", "r", stdin)

vi minT, maxT;
vi v;
int n, q;

void init()
{
	minT = vi(2 * n, INT_MAX);
	maxT = vi(2 * n, INT_MIN);
	for(int i = 2 * n - 1; i >= 1; i--)
	{
		if(i > n - 1)
			minT[i] = maxT[i] = v[i - n];
		else
		{
			minT[i] = min(minT[2 * i], minT[2 * i + 1]);
			maxT[i] = max(maxT[2 * i], maxT[2 * i + 1]);
		}
	}
}

int getMin(int l, int r, int curL, int curR, int index)
{
	if(curL >= l && curR <= r)
		return minT[index];
	else if(curL > r || curR < l)
		return INT_MAX;
	else
	{
		return min(getMin(l, r, curL, curL + (curR - curL) / 2, 2 * index), getMin(l, r, curL + (curR - curL) / 2 + 1, curR, 2 * index + 1));
	}
}

int getMax(int l, int r, int curL, int curR, int index)
{
	if(curL >= l && curR <= r)
		return maxT[index];
	else if(curL > r || curR < l)
		return INT_MIN;
	else
	{
		return max(getMax(l, r, curL, curL + (curR - curL) / 2, 2 * index), getMax(l, r, curL + (curR - curL) / 2 + 1, curR, 2 * index + 1));
	}
}

map<int, vi>pos;

int main()
{
	//readFile;
	while(cin >> n >> q)
	{
		ll z = 1;
		while(z < n)
			z *= 2;
		v.clear();
		v.resize(z);
		rep(i, 0, n)
		{
			cin >> v[i];
			pos[v[i]].pp(i + 1);
		}
		n = z;
		init();
		int l, r, x;
		int mini, maxi;
		rep(j, 0, q)
		{
			cin >> l >> r >> x;
			mini = getMin(l, r, 1, n, 1);
			maxi = getMax(l, r, 1, n, 1);
			if(mini == x && maxi == x)
			{
				cout << -1 << nl;
			}
			else if(mini != x)
			{
				cout << *lower_bound(pos[mini].begin(), pos[mini].end(), l) << nl;
			}
			else
			{
				cout << *lower_bound(pos[maxi].begin(), pos[maxi].end(), l) << nl;
			}
		}
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cstring>

using namespace std;

#define mp make_pair
#define pp push_back
#define Sort(x) sort(x.begin(), x.end())
#define rep(i, x, y) for(int i = x; i < y; ++i)
#define Rep(i, x, y) for(int i = x; i <= y; ++i)
#define dRep(i, x, y) for(int i = x;i >= y; --i)
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long
#define all(v) v.begin(),v.end()
#define ii pair<long long, long long>
#define mem(x, v) memset(x, v, sizeof(x))
#define nl '\n'
#define MOD 1000000007
#define readFile freopen("input.in", "r", stdin)

vi minT, maxT;
vi v;
vi firstSame;
int n, q;

int main()
{
	//readFile;
	while(cin >> n >> q)
	{
		v.clear();
		v.resize(n);
		firstSame.clear();
		firstSame.resize(n);
		rep(i, 0, n)
		{
			cin >> v[i];
			if(i)
			{
				if(v[i] == v[i - 1])
					firstSame[i] = firstSame[i - 1];
				else
					firstSame[i] = i;
			}
		}
		//n = z;
		int l, r, x;
		rep(j, 0, q)
		{
			cin >> l >> r >> x;
			l--, r--;
			if(firstSame[r] == firstSame[l] && v[l] == x)
				cout << -1 << nl;
			else
			{
				if(v[l] != x)
					cout << l + 1 << nl;
				else if(v[r] != x)
					cout << r + 1 << nl;
				else
					cout << firstSame[r] << nl;
			}
		}
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cstring>

using namespace std;

#define mp make_pair
#define pp push_back
#define Sort(x) sort(x.begin(), x.end())
#define rep(i, x, y) for(int i = x; i < y; ++i)
#define Rep(i, x, y) for(int i = x; i <= y; ++i)
#define dRep(i, x, y) for(int i = x;i >= y; --i)
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long
#define all(v) v.begin(),v.end()
#define ii pair<long long, long long>
#define mem(x, v) memset(x, v, sizeof(x))
#define nl '\n'
#define MOD 1000000007
#define readFile freopen("input.in", "r", stdin)

vi minT, maxT;
vi v;
int n, q;
ll z;

void init()
{
	minT = vi(2 * z, INT_MAX);
	maxT = vi(2 * z, INT_MIN);
	for(int i = 1; i <= n; i++)
	{
		maxT[i + z - 1] = v[i - 1], minT[i + z - 1] = v[i - 1];
	}

	for(int i = z - 1; i >= 1; i--)
	{
			minT[i] = min(minT[2 * i], minT[2 * i + 1]);
			maxT[i] = max(maxT[2 * i], maxT[2 * i + 1]);
	}
}

int getMin(int l, int r, int curL, int curR, int index)
{
	if(curL >= l && curR <= r)
		return minT[index];
	else if(curL > r || curR < l)
		return INT_MAX;
	else
	{
		return min(getMin(l, r, curL, curL + (curR - curL) / 2, 2 * index), getMin(l, r, curL + (curR - curL) / 2 + 1, curR, 2 * index + 1));
	}
}

int getMax(int l, int r, int curL, int curR, int index)
{
	if(curL >= l && curR <= r)
		return maxT[index];
	else if(curL > r || curR < l)
		return INT_MIN;
	else
	{
		return max(getMax(l, r, curL, curL + (curR - curL) / 2, 2 * index), getMax(l, r, curL + (curR - curL) / 2 + 1, curR, 2 * index + 1));
	}
}

set<int> pos[1000001];

int main()
{
	//readFile;
	while(cin >> n >> q)
	{
		z = 1;
		while(z < n)
			z *= 2;
		v.clear();
		v.resize(n);
		rep(i, 0, n)
		{
			cin >> v[i];
			pos[v[i]].insert(i + 1);
		}
		//n = z;
		init();
		int l, r, x;
		int mini, maxi;

		rep(j, 0, q)
		{
			cin >> l >> r >> x;
			mini = getMin(l, r, 1, z, 1);
			maxi = getMax(l, r, 1, z, 1);
			if(mini == x && maxi == x)
			{
				cout << -1 << nl;
			}
			else if(mini != x)
			{
				cout << *pos[mini].lower_bound(l) << nl;
			}
			else
			{
				cout << *pos[maxi].lower_bound(l) << nl;
			}
		}
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cstring>

using namespace std;

#define mp make_pair
#define pp push_back
#define Sort(x) sort(x.begin(), x.end())
#define rep(i, x, y) for(int i = x; i < y; ++i)
#define Rep(i, x, y) for(int i = x; i <= y; ++i)
#define dRep(i, x, y) for(int i = x;i >= y; --i)
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long
#define all(v) v.begin(),v.end()
#define ii pair<long long, long long>
#define mem(x, v) memset(x, v, sizeof(x))
#define nl '\n'
#define MOD 1000000007
#define readFile freopen("input.in", "r", stdin)

int v[200003];
int firstSame[200003];
int n, q;

int main()
{
	//readFile;
	while(cin >> n >> q)
	{
		rep(i, 0, n)
		{
			scanf("%i", &v[i]);
			//cin >> v[i];
			if(i)
			{
				if(v[i] == v[i - 1])
					firstSame[i] = firstSame[i - 1];
				else
					firstSame[i] = i;
			}
		}
		//n = z;
		int l, r, x;
		rep(j, 0, q)
		{
			scanf("%i %i %i", &l, &r, &x);
			//cin >> l >> r >> x;
			l--, r--;
			if(firstSame[r] == firstSame[l] && v[l] == x)
				printf("-1\n");
			else
			{
				if(v[l] != x)
					printf("%i\n",l + 1);
				else if(v[r] != x)
					printf("%i\n",r + 1);
				else
					printf("%i\n",firstSame[r]);

			}
		}
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cstring>

using namespace std;

#define mp make_pair
#define pp push_back
#define Sort(x) sort(x.begin(), x.end())
#define rep(i, x, y) for(int i = x; i < y; ++i)
#define Rep(i, x, y) for(int i = x; i <= y; ++i)
#define dRep(i, x, y) for(int i = x;i >= y; --i)
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long
#define all(v) v.begin(),v.end()
#define ii pair<long long, long long>
#define mem(x, v) memset(x, v, sizeof(x))
#define nl '\n'
#define MOD 1000000007
#define readFile freopen("input.in", "r", stdin)

vi minT, maxT;
vi v;
int n, q;
ll z;

void init()
{
	minT = vi(2 * z, INT_MAX);
	maxT = vi(2 * z, INT_MIN);
	for(int i = 1; i <= n; i++)
	{
		maxT[i + z - 1] = v[i - 1], minT[i + z - 1] = v[i - 1];
	}

	for(int i = z - 1; i >= 1; i--)
	{
			minT[i] = min(minT[2 * i], minT[2 * i + 1]);
			maxT[i] = max(maxT[2 * i], maxT[2 * i + 1]);
	}
}

int getMin(int l, int r, int curL, int curR, int index)
{
	if(curL >= l && curR <= r)
		return minT[index];
	else if(curL > r || curR < l)
		return INT_MAX;
	else
	{
		return min(getMin(l, r, curL, curL + (curR - curL) / 2, 2 * index), getMin(l, r, curL + (curR - curL) / 2 + 1, curR, 2 * index + 1));
	}
}

int getMax(int l, int r, int curL, int curR, int index)
{
	if(curL >= l && curR <= r)
		return maxT[index];
	else if(curL > r || curR < l)
		return INT_MIN;
	else
	{
		return max(getMax(l, r, curL, curL + (curR - curL) / 2, 2 * index), getMax(l, r, curL + (curR - curL) / 2 + 1, curR, 2 * index + 1));
	}
}

set<int> pos[1000001];

int main()
{
	//readFile;
	while(cin >> n >> q)
	{
		z = 1;
		while(z < n)
			z *= 2;
		v.clear();
		v.resize(n);
		rep(i, 0, n)
		{
			scanf("%i\n", &v[i]);
			//cin >> v[i];
			pos[v[i]].insert(i + 1);
		}
		//n = z;
		init();
		int l, r, x;
		int mini, maxi;

		rep(j, 0, q)
		{
			scanf("%i %i %i", &l, &r, &x);
			//cin >> l >> r >> x;
			mini = getMin(l, r, 1, z, 1);
			maxi = getMax(l, r, 1, z, 1);
			if(mini == x && maxi == x)
			{
				printf("-1\n");
				//cout << -1 << nl;
			}
			else if(mini != x)
			{
				printf("%i\n", *pos[mini].lower_bound(l));
				//cout << *pos[mini].lower_bound(l) << nl;
			}
			else
			{
				printf("%i\n", *pos[maxi].lower_bound(l));
				//cout << *pos[maxi].lower_bound(l) << nl;
			}
		}
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cstring>

using namespace std;

#define mp make_pair
#define pp push_back
#define Sort(x) sort(x.begin(), x.end())
#define rep(i, x, y) for(int i = x; i < y; ++i)
#define Rep(i, x, y) for(int i = x; i <= y; ++i)
#define dRep(i, x, y) for(int i = x;i >= y; --i)
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long
#define all(v) v.begin(),v.end()
#define ii pair<long long, long long>
#define mem(x, v) memset(x, v, sizeof(x))
#define nl '\n'
#define MOD 1000000007
#define readFile freopen("input.in", "r", stdin)

vi minT, maxT;
vi v;
vi firstSame;
int n, q;

int main()
{
	//readFile;
	while(cin >> n >> q)
	{
		v.clear();
		v.resize(n);
		firstSame.clear();
		firstSame.resize(n);
		rep(i, 0, n)
		{
			scanf("%i", &v[i]);
			//cin >> v[i];
			if(i)
			{
				if(v[i] == v[i - 1])
					firstSame[i] = firstSame[i - 1];
				else
					firstSame[i] = i;
			}
		}
		//n = z;
		int l, r, x;
		rep(j, 0, q)
		{
			cin >> l >> r >> x;
			l--, r--;
			if(firstSame[r] == firstSame[l] && v[l] == x)
				cout << -1 << nl;
			else
			{
				if(v[l] != x)
					cout << l + 1 << nl;
				else if(v[r] != x)
					cout << r + 1 << nl;
				else
					cout << firstSame[r] << nl;
			}
		}
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cstring>

using namespace std;

#define mp make_pair
#define pp push_back
#define Sort(x) sort(x.begin(), x.end())
#define rep(i, x, y) for(int i = x; i < y; ++i)
#define Rep(i, x, y) for(int i = x; i <= y; ++i)
#define dRep(i, x, y) for(int i = x;i >= y; --i)
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long
#define all(v) v.begin(),v.end()
#define ii pair<long long, long long>
#define mem(x, v) memset(x, v, sizeof(x))
#define nl '\n'
#define MOD 1000000007
#define readFile freopen("input.in", "r", stdin)

vi minT, maxT;
vi v;
vi firstSame;
int n, q;

int main()
{
	//readFile;
	while(cin >> n >> q)
	{
		v.clear();
		v.resize(n);
		firstSame.clear();
		firstSame.resize(n);
		rep(i, 0, n)
		{
			cin >> v[i];
			if(i)
			{
				if(v[i] == v[i - 1])
					firstSame[i] = firstSame[i - 1];
				else
					firstSame[i] = i;
			}
		}
		//n = z;
		int l, r, x;
		rep(j, 0, q)
		{
			cin >> l >> r >> x;
			l--, r--;
			if(firstSame[r] == firstSame[l] && v[l] == x)
				cout << -1 << nl;
			else
			{
				if(v[l] != x)
					cout << l + 1 << nl;
				else if(v[r] != x)
					cout << r + 1 << nl;
				else
					cout << firstSame[r] + 1 << nl;
			}
		}
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cstring>

using namespace std;

#define mp make_pair
#define pp push_back
#define Sort(x) sort(x.begin(), x.end())
#define rep(i, x, y) for(int i = x; i < y; ++i)
#define Rep(i, x, y) for(int i = x; i <= y; ++i)
#define dRep(i, x, y) for(int i = x;i >= y; --i)
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long
#define all(v) v.begin(),v.end()
#define ii pair<long long, long long>
#define mem(x, v) memset(x, v, sizeof(x))
#define nl '\n'
#define MOD 1000000007
#define readFile freopen("input.in", "r", stdin)

vi minT, maxT;
vi v;
int n, q;

void init()
{
	minT = vi(2 * n, INT_MAX);
	maxT = vi(2 * n, INT_MIN);
	for(int i = 2 * n - 1; i >= 1; i--)
	{
		if(i > n - 1)
			minT[i] = maxT[i] = v[i - n];
		else
		{
			minT[i] = min(minT[2 * i], minT[2 * i + 1]);
			maxT[i] = max(maxT[2 * i], maxT[2 * i + 1]);
		}
	}
}

int getMin(int l, int r, int curL, int curR, int index)
{
	if(curL >= l && curR <= r)
		return minT[index];
	else if(curL > r || curR < l)
		return INT_MAX;
	else
	{
		return min(getMin(l, r, curL, curL + (curR - curL) / 2, 2 * index), getMin(l, r, curL + (curR - curL) / 2 + 1, curR, 2 * index + 1));
	}
}

int getMax(int l, int r, int curL, int curR, int index)
{
	if(curL >= l && curR <= r)
		return maxT[index];
	else if(curL > r || curR < l)
		return INT_MIN;
	else
	{
		return max(getMax(l, r, curL, curL + (curR - curL) / 2, 2 * index), getMax(l, r, curL + (curR - curL) / 2 + 1, curR, 2 * index + 1));
	}
}

vi pos[1000001];

int main()
{
	//readFile;
	while(cin >> n >> q)
	{
		ll z = 1;
		while(z < n)
			z *= 2;
		v.clear();
		v.resize(z);
		rep(i, 0, n)
		{
			cin >> v[i];
			pos[v[i]].pp(i + 1);
		}
		n = z;
		init();
		int l, r, x;
		int mini, maxi;
		rep(j, 0, q)
		{
			cin >> l >> r >> x;
			mini = getMin(l, r, 1, n, 1);
			maxi = getMax(l, r, 1, n, 1);
			if(mini == x && maxi == x)
			{
				cout << -1 << nl;
			}
			else if(mini != x)
			{
				cout << *lower_bound(pos[mini].begin(), pos[mini].end(), l) << nl;
			}
			else
			{
				cout << *lower_bound(pos[maxi].begin(), pos[maxi].end(), l) << nl;
			}
		}
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cstring>

using namespace std;

#define mp make_pair
#define pp push_back
#define Sort(x) sort(x.begin(), x.end())
#define rep(i, x, y) for(int i = x; i < y; ++i)
#define Rep(i, x, y) for(int i = x; i <= y; ++i)
#define dRep(i, x, y) for(int i = x;i >= y; --i)
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long
#define all(v) v.begin(),v.end()
#define ii pair<long long, long long>
#define mem(x, v) memset(x, v, sizeof(x))
#define nl '\n'
#define MOD 1000000007
#define readFile freopen("input.in", "r", stdin)

int v[200003];
int firstSame[200003];
int n, q;

int main()
{
	//readFile;
	while(cin >> n >> q)
	{
		rep(i, 0, n)
		{
			scanf("%i", &v[i]);
			//cin >> v[i];
			if(i)
			{
				if(v[i] == v[i - 1])
					firstSame[i] = firstSame[i - 1];
				else
					firstSame[i] = i;
			}
		}
		//n = z;
		int l, r, x;
		rep(j, 0, q)
		{
			cin >> l >> r >> x;
			l--, r--;
			if(firstSame[r] == firstSame[l] && v[l] == x)
				cout << -1 << nl;
			else
			{
				if(v[l] != x)
					cout << l + 1 << nl;
				else if(v[r] != x)
					cout << r + 1 << nl;
				else
					cout << firstSame[r] << nl;
			}
		}
	}
	return 0;
}


//#include <numeric>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <deque>
#include <string>
#include <string.h>
#include <vector>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <time.h>
#include <bitset>
#include <list>
#include <limits>
using namespace std;

typedef long long ll;//don't write as long!!!
typedef unsigned long long ull;
typedef map<int,int> mii;

double EPS = 1e-9;
int INF = 0x7FFFFFFF;//numeric_limits<int>::max();
long long INFF = 0x7FFFFFFFFFFFFFFF;//numeric_limits<long long>::max();
double PI = acos(-1.0);

#define SIZE(v) (int)v.size()
#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))

//all zero
#define REP(i,n) FOR(i,0,n)
#define REPS(i,s) for(int i = 0;s[i]!='\0';++i)
#define REPV(i,v) FOR(i,0,SIZE(v))
#define REPN(i,n) FORN(i,0,n)
#define REPD(i,n) FORD(i,n,0)
#define REPI(t,v,i) for(t::iterator i=v.begin();i!=v.end();i++)
#define REPI2(t1,t2,v,i) for(t1,t2::iterator i=v.begin();i!=v.end();i++)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define FIND(m,i) m.find(i)!=m.end()
#define UNFIND(m,i) !(FIND(m,i))

#pragma region Functions

inline void scanf(int &d1){scanf("%d",&d1);}
inline void scanf(int &d1,int &d2){scanf("%d%d",&d1,&d2);}
inline void scanf(int &d1,int &d2,int &d3){scanf("%d%d%d",&d1,&d2,&d3);}
inline void scanf(ll &d1){scanf("%I64d",&d1);}
inline void scanf(ll &d1,ll &d2){scanf("%I64d%I64d",&d1,&d2);}
inline void scanf(ll &d1,ll &d2,ll &d3){scanf("%I64d%I64d%I64d",&d1,&d2,&d3);}
inline void scanf(double &d1){scanf("%lf",&d1);}
inline void scanf(char *temp){scanf("%s",temp);}

inline void printf(int d1){printf("%d\n",d1);}
inline void printf(int d1,int d2){printf("%d %d\n",d1,d2);}
inline void printf(double f1){printf("%.17g\n",f1);}
inline void printf(ll l1){printf("%I64d\n",l1);}
inline void printf(ll l1,ll l2){printf("%I64d %I64d\n",l1,l2);}
inline void printfcase(int id){printf("Case #%d:",id);}

inline string tostring(int a){char x[100];sprintf(x,"%d",a); string s = x;return s;}
inline void toupperstring(string &s){REPV(i,s){if(s[i]>='a'&&s[i]<='z'){s[i]=s[i]-'a'+'A';}}}//transform(s.begin(),s.end(),s.begin(),::toupper);
inline void tolowerstring(string &s){REPV(i,s){if(s[i]>='A'&&s[i]<='Z'){s[i]=s[i]-'A'+'a';}}}//transform(s.begin(),s.end(),s.begin(),::tolower);
inline int toint(string a){char x[100];int res;strcpy(x,a.c_str());sscanf(x,"%d",&res);return res;}

inline void freopen(string sin,string sout){freopen(sin.c_str(),"r",stdin);freopen(sout.c_str(),"w",stdout);}

template<typename T1, typename T2,typename T>
inline typename T::iterator findorinsert(T &m,const T1& t1,const T2 & t2){
	typename T::iterator iter = m.find(t1);
	if(iter == m.end()){m.insert(mp(t1,t2));return m.find(t1);}
	else{return iter;}
}

template<typename T>
inline T gcd(T u, T v){while(v != 0){T r = u%v;u = v;v = r;}return u;}

#pragma endregion

#pragma region Structs & Classes

template<typename T,int n>
struct Vector{
	T data[n];
	void read(){REP(i,n){cin>>data[i];}}
	inline T operator*(const Vector<T,n> &v) const{
		T res = 0;REP(i,n){res+=data[i]*v[i];}return res;
	}
	inline Vector<T,n> operator+(const Vector<T,n> &v) const{
		Vector<T,n> res;REP(i,n){res[i]=data[i]+v[i];}return res;
	}
	inline Vector<T,n> operator-(const Vector<T,n> &v) const{
		Vector<T,n> res;REP(i,n){res[i]=data[i]-v[i];}return res;
	}
	inline bool operator<(const Vector<T,n> &v) const{
		REP(i,n){if(data[i]!=v[i]){return data[i]<v[i];}}return false;
	}
	inline bool operator==(const Vector<T,n> &v) const{
		REP(i,n){if(data[i]!=v[i]){return false;}}return true;
	}
	inline T& operator[](int id){return data[id];}
	inline T operator[](int id) const{return data[id];}
	inline int size()const{return n;}
};

typedef Vector<int,2> Vi2;
template<typename T>
inline Vector<T,2> make_vector(const T &t1,const T &t2){Vector<T,2> res = {t1,t2};return res;}
template<typename T>
inline Vector<T,3> make_vector(const T &t1,const T &t2,const T &t3){Vector<T,3> res = {t1,t2,t3};return res;}
#define mv make_vector
Vi2 dirs[4] = {{0,1},{0,-1},{1,0},{-1,0}};//y,x

template<int n,int m>//2n/lgn
class Prime{
public:
	Prime(int num){sieve();collect();}
	int find1factor(int num) const{
		REP(i,results_size){if(num%results[i] == 0){return results[i];}}return num;
	}
	bool bits[n+1];int results[m],result_size;
private:
	void sieve(){
		RESET(bits,true);bits[0] = false;bits[1] = false;
		for(int i = 2;i <= n;++i){
			if(bits[i]){
				for(int j = i+i;j <= n;j+=i){bits[j] = false;}
			}
		}
	}
	void collect(){
		for(int i = 2;i <= n;++i){if(bits[i]){results[result_size]=i;result_size++}}
	}
};

template<int n,int m>
struct Graph{
	int head[n],edge_id;
	struct{
		int to,next;
	}edges[m];
	void init(int num = n){edge_id = 0;memset(head,-1,sizeof(int)*num);}//!!
	int add(int from,int to){
		edges[edge_id].next = head[from];edges[edge_id].to = to;
		head[from] = edge_id;edge_id++;return head[from];
	}
	inline int next(int edge) const{return edges[edge].next;}
	inline int to(int edge) const{return edges[edge].to;}
};

#define REPG(g,id,e) for(int e = g.head[id];e != -1;e = g.next(e))

#pragma endregion

const int max_n = 200000;
int n,m;
Vi2 data[max_n];

int main(){
	scanf(n,m);
	int last = -1,startpos = -1;
	REP(i,n){
		scanf(data[i][0]);
		if(data[i][0]==last){
			data[i][1] = startpos;
		}
		else{
			last = data[i][0];
			startpos = i;
			data[i][1] = startpos;
		}
	}
	REP(i,m){
		int l,r,x;
		scanf(l,r,x);
		l--;
		r--;
		bool find = false;
		while(r>=l){
			if(data[r][0]!=x){
				printf(r+1);
				find = true;
				break;
			}
			else{
				r = data[r][1]-1;
			}
		}
		if(!find){
			printf(-1);
		}
	}
	return 0;
}