#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
ll n,m;
ll r[N],d[N],s[N],t[N],cnt[N],need[N];
bool check(int x){
memset(cnt,0,sizeof(cnt));
for(int i = 1;i <= x;i++){
cnt[s[i]] += d[i];
cnt[t[i] + 1] -= d[i];
}
for(int i = 1;i <= n;i++){
need[i] = need[i - 1] + cnt[i];
if(need[i] > r[i]) return false;
}
return true;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 1;i <= n;i++) cin >> r[i];
for(int i = 1;i <= m;i++) cin >> d[i] >> s[i] >> t[i];
ll l = 0,r = m - 1,mid;
while(l < r){
mid = l + r + 1 >> 1;
if(check(mid)) l = mid;
else r = mid - 1;
}
if(l == m - 1){
cout << "0" << endl;
}else{
cout << "-1" << endl << mid << endl;
}
return 0;
}