import bisect N, M = map(int, input().split()) L = list(map(int, input().split())) FBW = [list(map(int, input().split())) for _ in range(M)] ans = 0 for f, b, w in FBW: pos = bisect.bisect_left(L, f) if pos0: c = min(c, f-L[pos-1]) ans += max(b, w-c) else: c = f-L[pos-1] ans += max(b, w-c) print(ans)