import bisect INF = 10 ** 17 N, M = map(int, input().split()) L = list(map(int, input().split())) Li = [] Li.append(-INF) for x in L: Li.append(x) Li.append(INF) ans = 0 for i in range(M): F, B, W = map(int, input().split()) idx = bisect.bisect_left(Li, F) min_dist = abs(F - Li[idx]) idx -= 1 min_dist = min(min_dist, abs(F - Li[idx])) if min_dist < W - B: ans += W - min_dist else: ans += B print(ans)