#include <bits/stdc++.h>
using namespace std;
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
  s << "{";
  for (int i = 0; i < t.size(); i++)
    s << t[i] << (i == t.size() - 1 ? "" : ",");
  return s << "}" << endl;
}
int koszt[200000];
pair<pair<int, int>, int> wys[200000];
priority_queue<pair<int, int> > Q;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> koszt[i];
  long long wyn = 0;
  for (int i = 0; i < m; i++) {
    cin >> wys[i].first.first >> wys[i].first.second >> wys[i].second;
    wys[i].first.first--;
    wys[i].first.second--;
    wyn += wys[i].second;
  }
  sort(wys, wys + m);
  int l = 0;
  for (int i = 0; i < n; i++) {
    while (l < m && wys[l].first.first == i) {
      Q.push(make_pair(-wys[l].first.second, wys[l].second));
      l++;
    }
    while (koszt[i] && !Q.empty()) {
      pair<int, int> u = Q.top();
      Q.pop();
      u.first = -u.first;
      if (u.first < i) continue;
      int f = min(u.second, koszt[i]);
      u.second -= f;
      koszt[i] -= f;
      wyn -= f;
      if (u.second) Q.push(make_pair(-u.first, u.second));
    }
  }
  cout << wyn;
  return 0;
}
