import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd n,m = map(int,input().split()) l = [-10**18] + list(map(int,input().split())) + [10**18] ans = 0 for i in range(m): f,bi,wi = map(int,input().split()) t = bisect_right(l, f) d = min(l[t]-f, f-l[t-1]) ans += max(bi, wi-d) print(ans)