n, m = map(int, input().split()) L = list(map(int, input().split())) s, c = 0, 0 for _ in range(m): f, b, w = map(int, input().split()) distance = min(abs(f - lake) for lake in L) if distance == 0: s += w else: cost = distance if w - cost > b: s += w c += cost else: s += b print(s - c)