from bisect import bisect_left, bisect_right

N, M = map(int, input().split())
L = list(map(int, input().split()))
FBW = [list(map(int, input().split())) for _ in range(M)]

ans = 0
for i in range(M):
    f, b, w = FBW[i]
    idx = bisect_left(L, f)
    if idx != N and L[idx] == f:
        ans += w
    # if f in L:
    # ans += w
    else:
        idx = bisect_left(L, f)
        if idx == 0:
            cost = L[0] - f
        elif idx == N:
            cost = f - L[-1]
        else:
            near = L[bisect_left(L, f)]
            near2 = L[bisect_right(L, f) - 1]
            cost = min(abs(f - near), abs(f - near2))
        ans += max(w - cost, b)
print(ans)