program cojs1266;
var
room,d,s,t,sum:array[0..1000000] of longint;
n,m,l,r,now,k,ssum,i:longint;
f:boolean;
begin
assign(input,'classrooms.in');
assign(output,'classrooms.out');
reset(input);
rewrite(output);
readln(n,m);
for i:=1 to n do
read(room[i]);
for i:=1 to m do
readln(d[i],s[i],t[i]);
now:=0;
l:=0; r:=m+1;
while l<>r do
begin
f:=true;
k:=(l+r) div 2;
if k>now then
for i:=now+1 to k do
begin
sum[s[i]]:=sum[s[i]]+d[i];
sum[t[i]+1]:=sum[t[i]+1]-d[i];
end
else
for i:=k+1 to now do
begin
sum[s[i]]:=sum[s[i]]-d[i];
sum[t[i]+1]:=sum[t[i]+1]+d[i];
end;
now:=k;
ssum:=0;
for i:=1 to n do
begin
inc(ssum,sum[i]);
if ssum>room[i] then
begin
f:=false;
break;
end;
end;
if f then l:=k+1
else
r:=k;
end;
if (k=m)and(f) then
writeln(0)
else
begin
writeln(-1);
writeln(l);
end;
close(input);
close(output);
end.