#include <bits/stdc++.h>
using namespace std;
struct T {
  int x, y, p;
  bool operator<(const T &b) const { return y < b.y; }
};
T a[211111];
long long ans = 0;
int n, m, c[211111];
multiset<T> h;
bool my(T a, T b) { return a.x < b.x; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].p);
    ans += a[i].p;
  }
  sort(a + 1, a + 1 + m, &my);
  int j = 1;
  for (int i = 1; i <= n; i++) {
    while (j <= m && a[j].x == i) h.insert(a[j]), ++j;
    while (c[i] > 0 && h.size() > 0) {
      T p = *h.begin();
      h.erase(h.begin());
      if (p.y < i) continue;
      int mi = ((p.p) < (c[i]) ? (p.p) : (c[i]));
      c[i] -= mi;
      p.p -= mi;
      ans -= mi;
      if (p.p > 0) h.insert(p);
    }
  }
  cout << ans << endl;
  return 0;
}
