#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iterator>
#include<stack>
using namespace std;
typedef __int64 LL;
const int INF=1e9+7;
const double eps=1e-7;
const int maxn=2*100000;
int n,m,dp[maxn+10],a[maxn+10];
void pre()
{
dp[1]=1;
for(int i=2;i<=n;i++)
{
dp[i]=a[i]==a[i-1]?dp[i-1]:i;
}
}
void work()
{
int le,ri,x;
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&le,&ri,&x);
if(a[ri]!=x)
{
printf("%d\n",ri);
continue;
}
int p=dp[ri]-1;
if(p<le) {puts("-1");continue;}
printf("%d\n",p);
}
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
pre();
work();
}
return 0;
}