#include <bits/stdc++.h>
using namespace std;
const int N = 200003;
int c[N];
vector<pair<int, int> > v[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", c + i);
  long long res = 0;
  while (m--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    v[a].push_back(pair<int, int>(b, c));
    res += c;
  }
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      Q;
  for (int i = 1; i <= n; ++i) {
    while (!v[i].empty()) {
      Q.push(v[i].back());
      v[i].pop_back();
    }
    while (!Q.empty() && Q.top().first < i) Q.pop();
    while (c[i] && !Q.empty()) {
      pair<int, int> p = Q.top();
      Q.pop();
      int x = min(c[i], p.second);
      res -= x;
      c[i] -= x;
      p.second -= x;
      if (p.second) Q.push(p);
    }
  }
  printf("%lld\n", res);
  return 0;
}
