#include <bits/stdc++.h>
using namespace std;
int n, m, a[200005];
vector<pair<int, int> > g[200005];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  long long rs = 0;
  for (int i = 1; i <= m; ++i) {
    int l, r, w;
    cin >> l >> r >> w;
    g[l].push_back({r, w});
    rs += w;
  }
  for (int i = 1; i <= n; ++i) {
    while (q.empty() == false && q.top().first < i) q.pop();
    for (int j = 0; j < g[i].size(); ++j) {
      pair<int, int> t = g[i][j];
      q.push(t);
    }
    while (a[i] > 0 && q.empty() == false) {
      pair<int, int> t = q.top();
      q.pop();
      int x = min(t.second, a[i]);
      a[i] -= x;
      t.second -= x;
      rs -= x;
      if (t.second > 0) q.push(t);
    }
  }
  cout << rs;
  return 0;
}
