import sys input = sys.stdin.readline from bisect import * N, M = map(int, input().split()) inf = 10 ** 18 L = [-inf] + list(map(int, input().split())) + [inf] ans = 0 for i in range(M): F, B, W = map(int, input().split()) ind = bisect_right(L, F) ans += max(B, W - min(L[ind] - F, F - L[ind - 1])) print(ans)