from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,M = map(int,input().split()) L = list(map(int,input().split())) X = [] s = 0 for _ in range(M): f,b,w = map(int,input().split()) s += b is_ok = lambda x: L[x]<=f if is_ok(N-1): x = N-1 X.append(w-b-abs(L[x]-f)) continue if not is_ok(0): X.append(w-b-abs(L[0]-f)) continue y = N-1 x = 0 while y-x>1: mid = (y+x)//2 if is_ok(mid): x = mid else: y = mid X.append(w-b-min(abs(L[x]-f),abs(L[y]-f))) X.sort(reverse=True) for x in X: if x<=0: break s += x print(s)