#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int> > q;
vector<pair<int, int> > r[210000];
int a[210000];
int n, m;
long long ans = 0;
int main() {
  int i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    r[x].push_back(make_pair(-y, z));
    ans += z;
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < r[i].size(); j++) q.push(r[i][j]);
    while (!q.empty() && -q.top().first < i) q.pop();
    while (!q.empty() && a[i]) {
      pair<int, int> tmp = q.top();
      q.pop();
      int k = min(tmp.second, a[i]);
      tmp.second -= k;
      a[i] -= k;
      ans -= k;
      if (tmp.second) q.push(tmp);
    }
  }
  cout << ans << endl;
}
