#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, m;
int cost[maxn];
long long ans;
vector<pair<int, int> > g[maxn];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> cost[i];
  for (int i = 1; i <= m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].push_back(make_pair(b, c));
    ans += c;
  }
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  for (int i = 1; i <= n; ++i) {
    while (!pq.empty() && pq.top().first < i) pq.pop();
    for (int j = 0; j < g[i].size(); ++j) pq.push(g[i][j]);
    while (cost[i] && !pq.empty()) {
      pair<int, int> t = pq.top();
      pq.pop();
      int d = min(t.second, cost[i]);
      cost[i] -= d;
      t.second -= d;
      ans -= d;
      if (t.second) pq.push(t);
    }
  }
  cout << ans;
  return 0;
}
