#include <bits/stdc++.h>
using namespace std;
int r[200200];
pair<pair<int, int>, int> t[200200];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (n); i++) scanf("%d", &r[i]);
  for (int i = 0; i < (m); i++)
    scanf("%d%d%d", &t[i].first.first, &t[i].first.second, &t[i].second);
  sort(t, t + m);
  long long res = 0;
  for (int i = 0; i < (m); i++) {
    t[i].first.first--;
    t[i].first.second--;
    res += t[i].second;
  }
  int cur = 0;
  multiset<pair<int, int> > all;
  for (int i = 0; i < n; i++) {
    while (cur < m && t[cur].first.first == i) {
      all.insert(make_pair(t[cur].first.second, t[cur].second));
      cur++;
    }
    while (all.size() > 0 && all.begin()->first < i) all.erase(all.begin());
    while (r[i] > 0 && all.size() > 0) {
      pair<int, int> p = *all.begin();
      all.erase(all.begin());
      int flow = min(r[i], p.second);
      res -= flow;
      p.second -= flow;
      r[i] -= flow;
      if (p.second > 0) all.insert(p);
    }
  }
  cout << res << endl;
}
