#int(input()) #map(int, input().split()) #list(map(int, input().split())) N, M = map(int, input().split()) L = list(map(int, input().split())) F = [0] * M for i in range(M): F[i] = list(map(int, input().split())) ans = 0 import bisect for i in range(M): f, b, w = F[i] t = bisect.bisect(L, f) if t == 0: ans += max(b, w-abs(f-L[0])) elif t == N: ans += max(b, w-abs(f-L[-1])) else: ans += max(b, w-abs(f-L[t]), w-abs(f-L[t-1])) print(ans)