#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10;
int n, m, r[N], d[N], s[N], t[N], c[N];
bool check(int x) {
for (int i = 1; i <= n; i++) c[i] = 0;
for (int i = 1; i <= x; i++) c[s[x]] += d[x], c[t[x]+1] -= d[x];
for (int i = 1; i <= x; i++) {
c[i] += c[i-1];
if (c[i] > r[i]) return false;
}
return true;
}
signed main() {
freopen("classrooms.in", "r", stdin);
freopen("classrooms.out", "w", stdout);
ios::sync_with_stdio(0);
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];
int l = 1, r = n;
while (l < r) {
int mid = (l + r + 1) / 2;
if (check(mid)) l = mid;
else r = mid - 1;
}
if (l == n) cout << 0;
else cout << -1 << "\n" << l + 1;
return 0;
}