#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
int val[N];
vector<pair<int, int> > adj[N];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    Q;
int main() {
  int n, m, x, y, z;
  long long sum = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> val[i];
  for (int i = 1; i <= m; ++i) {
    cin >> x >> y >> z;
    adj[x].push_back(make_pair(y, z)), sum += z;
  }
  for (int i = 1; i <= n; ++i) {
    while (!Q.empty() && Q.top().first < i) Q.pop();
    for (int j = 0; j < adj[i].size(); ++j) Q.push(adj[i][j]);
    while (!Q.empty() && val[i]) {
      pair<int, int> T = Q.top();
      Q.pop();
      int tmp = min(T.second, val[i]);
      T.second -= tmp, val[i] -= tmp, sum -= tmp;
      if (T.second) Q.push(T);
    }
  }
  cout << sum << endl;
  return 0;
}
