from bisect import bisect_left n,m = map(int,input().split()) l = list(map(int,input().split())) ans = 0 for _ in range(m): f,b,w = map(int,input().split()) i = bisect_left(l,f) c = 0 if i0: c = min(c,f-l[i-1]) if i