from bisect import bisect_left import sys input = sys.stdin.readline n, m = map(int, input().split()) L = list(map(int, input().split())) ans = 0 for _ in range(m): f, b, w = map(int, input().split()) idx = bisect_left(L, f) res = b if idx < n: res = max(res, w - (L[idx] - f)) if idx > 0: res = max(res, w - (f - L[idx - 1])) ans += res print(ans)