n,m = map(int,input().split()) L = [-10**10]+list(map(int,input().split()))+[10**10] FBW = [list(map(int,input().split())) for i in range(m)] FBW.sort() ans = 0 now = 0 for f,b,w in FBW: while now < n+2 and L[now] < f: now += 1 dist = min(f-L[now-1],L[now]-f) ans += max(w-dist,b) print(ans)