1 #include<bits/stdc++.h>
2 using namespace std;
3 const int maxn=1000005;
4 int n,m,x,y,num,i;
5
6 struct Edge{
7 int l,r,w,f,mn;
8 }tree[maxn<<2];
9
10 char Cget;
11 inline void read(int &now)
12 {
13 now=0; Cget=getchar();
14 while(Cget>'9'||Cget<'0') Cget=getchar();
15 while(Cget>='0'&&Cget<='9') now=now*10+Cget-'0',Cget=getchar();
16 }
17
18 inline int min(int a,int b) { return a<b?a:b;}
19
20 inline void tree_down(int k)
21 {
22 tree[k<<1].f+=tree[k].f,tree[k<<1|1].f+=tree[k].f;
23 tree[k<<1].mn-=tree[k].f,tree[k<<1|1].mn-=tree[k].f;
24 tree[k].f=0;
25 }
26
27 void tree_build(int l,int r,int k)
28 {
29 tree[k].l=l,tree[k].r=r;
30 if(l==r)
31 {
32 read(tree[k].mn);
33 return ;
34 }
35 int mid=(l+r)>>1;
36 tree_build(l,mid,k<<1);
37 tree_build(mid+1,r,k<<1|1);
38 tree[k].mn=min(tree[k<<1].mn,tree[k<<1|1].mn);
39 }
40
41 void tree_change(int l,int r,int k,int to)
42 {
43 if(tree[k].l>=l&&tree[k].r<=r)
44 {
45 if(tree[k].mn<to)
46 {
47 printf("-1
%d
",i);
48 exit(0);
49 }
50 tree[k].mn-=to,tree[k].f+=to;
51 return ;
52 }
53 if(tree[k].f) tree_down(k);
54 int mid=(tree[k].l+tree[k].r)>>1;
55 if(r<=mid) tree_change(l,r,k<<1,to);
56 else if(l>mid) tree_change(l,r,k<<1|1,to);
57 else{
58 tree_change(l,mid,k<<1,to);
59 tree_change(mid+1,r,k<<1|1,to);
60 }
61 tree[k].mn=min(tree[k<<1].mn,tree[k<<1|1].mn);
62 }
63
64 int main()
65 {
66 read(n),read(m);
67 tree_build(1,n,1);
68 for(i=1;i<=m;i++)
69 {
70 read(num),read(x),read(y);
71 tree_change(x,y,1,num);
72 }
73 puts("0");
74 return 0;
75 }