import sys input = lambda :sys.stdin.readline()[:-1] from bisect import bisect_left, bisect, insort_left, insort def main(): N, M = map(int, input().split()) L = list(map(int, input().split())) L.sort() L = [float("-inf")] + L + [float("inf")] # 左右に無限大つけることでindex errorを回避 # print(L) fbw = [list(map(int, input().split())) for _ in range(N)] sg = 0 cost = 0 for i in range(M): # 二分探索使う idx = bisect_left(L, fbw[i][0]) if min(fbw[i][0] - L[idx - 1], L[idx] - fbw[i][0]) < fbw[i][2] - fbw[i][1]: sg += fbw[i][2] cost += min(fbw[i][0] - L[idx - 1], L[idx] - fbw[i][0]) else: sg += fbw[i][1] print(sg - cost) if __name__ == '__main__': main()