import bisect def main(): n,m=map(int,input().split()) ls=list(map(int,input().split())) ans = 0 for i in range(m): f,b,w=map(int,input().split()) idx = bisect.bisect(ls,f) cost = 10**10 if idx < n: cost1 = abs(f-ls[idx]) if cost1 < cost: cost = cost1 if 0 <= idx-1: cost2 = abs(f-ls[idx-1]) if cost2 < cost: cost = cost2 if cost < w-b: ans += w - cost else: ans += b print(ans) if __name__ == "__main__": main()