from bisect import bisect_left def find_nearest(a: list[int], v: int) -> int: """ソート済みリスト a の要素のうち、v との差が最も小さい要素を返す""" assert len(a) > 0 p = bisect_left(a, v) if p == len(a): return a[-1] if p > 0 and v-a[p-1] <= a[p]-v: return a[p-1] return a[p] N, M = map(int, input().split()) L = list(map(int, input().split())) xs = [] for _ in range(M): F, B, W = map(int, input().split()) xs.append((F, B, W)) lakes = set(L) ans = 0 for f, b, w in xs: t = 0 if f in lakes: t = w else: t = b # 水に移動する d = abs(f - find_nearest(L, f)) t = max(t, w - d) ans += t print(ans)