import bisect n, m = map(int, input().split()) L = list(map(int, input().split())) F = [] B = [] W = [] for _ in range(m): li = list(map(int, input().split())) F.append(li[0]) B.append(li[1]) W.append(li[2]) total_cost = 0 is_move = [False]*m for i in range(m): ind_1 = bisect.bisect_left(L, F[i]) if ind_1>0 and ind_1 < n: ind_2 = ind_1 - 1 cost = min(abs(F[i]-L[ind_1]), abs(F[i]-L[ind_2])) if cost < (W[i]-B[i]) : is_move[i] = True total_cost += cost else: continue elif ind_1 == 0: cost = abs(F[i]-L[ind_1]) if cost < (W[i]-B[i]) : is_move[i] = True total_cost += cost elif ind_1 == n: cost = abs(F[i]-L[ind_1-1]) if cost < (W[i]-B[i]) : is_move[i] = True total_cost += cost total_score = 0 for j in range(m): if is_move[j]: total_score += W[j] else: total_score += B[j] total_score -= total_cost print(total_score)