#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:6031)
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int n, m, r, d, s, t;
int arr[1000000 + 10];
int b[1000000 + 10];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
scanf("%d", &arr[i]);
for (int i = 1; i <= n; i++)
b[i] = arr[i] - arr[i - 1];
int ss = 0;
while (++ss < m)
{
scanf("%d %d %d", &d, &s, &t);
b[s] -= d;
b[t + 1] += d;
for (int i = 1; i <= n; i++)
{
if ((arr[i] = arr[i - 1] + b[i]) < 0)
{
printf("-1\n");
cout << ss << endl;
exit(0);
}
}
}
if (ss== m)
cout << '0' << endl;
return 0;
}