from bisect import bisect_left n, m = map(int, input().split()) L = sorted(map(int, input().split())) s, c = 0, 0 for _ in range(m): f, b, w = map(int, input().split()) i = bisect_left(L, f) distance = float('inf') if i < n: distance = abs(f - L[i]) if i > 0: distance = min(distance, abs(f - L[i - 1])) if distance == 0: s += w else: if w - distance > b: s += w c += distance else: s += b print(s - c)