from bisect import * 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: a = bisect_left(L, f) tmp = b if a > 0: tmp = max(tmp, w - f + L[a - 1]) if a < N: tmp = max(tmp, w - L[a] + f) ans += tmp print(ans)