#include<bits/stdc++.h>
using namespace std;
int n,m;
int d[1000005],s[1000005],t[1000005];
int b[1000005];
int check(int l,int k){
for(int i=l;i<=k;i++){
for(s[i];s[i]<=t[i];s[i]++){
b[s[i]]-=d[i];
if(b[s[i]]<0)return i;
}
}
return 0;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>b[i];
for(int i=1;i<=m;i++)cin>>d[i]>>s[i]>>t[i];
int low=1,high=m;
while(low<high){
int mid=(low+high)/2;
if(check(low,mid)){
cout<<"-1"<<endl<<check(low,mid);
return 0;
}
if(!check(low,mid)){
low=mid+1;
}
}
cout<<"0";
return 0;
}