#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m, F, B, W; cin >> n >> m; vector L(n + 2); for(int i = 1; i <= n; i++) cin >> L[i]; L.back() = (1ll << 31) - 1, L[0] = -(1 << 30); auto f = [&](int pos){ int p = lower_bound(L.begin(), L.end(), pos) - L.begin(); return min(L[p] - pos, pos - L[p - 1]); }; ll ans = 0; while(m--){ cin >> F >> B >> W; ans += max(B, W - f(F)); } cout << ans << '\n'; }