from collections import * import heapq import bisect INF = float("inf") N, M = map(int, input().split()) L = [-INF] + list(map(int, input().split())) + [INF] ans = 0 for _ in range(M): F, B, W = map(int, input().split()) pl = bisect.bisect_left(L, F) ans += max(B, W - min(L[pl] - F, F - L[pl - 1])) # print(F, B, W - min(L[pl] - F, F - L[pl - 1])) print(ans)