from bisect import bisect_left N,M = map(int,input().split()) INFTY = 10**9 L = [-INFTY]+list(map(int,input().split()))+[2*INFTY] A = [list(map(int,input().split())) for _ in range(M)] ans = 0 for j in range(M): f,b,w = A[j] ind = bisect_left(L,f) d = min(abs(L[ind]-f),abs(L[ind-1]-f)) if d==0: ans += w else: if w-b-d>0: ans += w-d else: ans += b print(ans)