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()) k = bisect_left(L, F) res = B if k > 0: res = max(res, W-(F-L[k-1])) if k < N: res = max(res, W-(L[k]-F)) ans += res print(ans)