#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, w;
  bool operator<(const node &b) const { return l < b.l; }
} b[200010];
struct Point {
  int r, w;
  bool operator<(const Point &b) const { return r > b.r; }
} temp;
priority_queue<Point> c;
int a[200010];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  long long ans = 0LL;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &b[i].l, &b[i].r, &b[i].w);
    ans += b[i].w;
  }
  sort(b + 1, b + 1 + m);
  int now = 1;
  while (!c.empty()) c.pop();
  for (int i = 1; i <= n; i++) {
    while (!c.empty()) {
      temp = c.top();
      if (temp.r < i)
        c.pop();
      else
        break;
    }
    while (now <= m && i == b[now].l) {
      temp.r = b[now].r;
      temp.w = b[now].w;
      c.push(temp);
      now++;
    }
    while (a[i] && (!c.empty())) {
      temp = c.top();
      c.pop();
      int x = min(a[i], temp.w);
      a[i] -= x;
      temp.w -= x;
      ans -= x;
      if (temp.w) c.push(temp);
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
