

d,n = gets.split(" ").map(&:to_i)
t = Array.new(d)
for i in 0...d
	t[i] = gets.to_i
end
a = Array.new(n)
b = Array.new(n)
c = Array.new(n)
for i in 0...n
	a[i],b[i],c[i] = gets.split(" ").map(&:to_i)
end
dp = Array.new(n)
for i in 0...n
	if a[i] <= t[0] && t[0] <= b[i]
		dp[i] = 0
	else
		dp[i] = -1
	end
end
for i in 1...d
	dpw = Array.new(n,0)
	for j in 0...n
		if a[j] <= t[i] && t[i] <= b[j]
			dpw[j] = 0
			for k in 0...n
				if dp[k] >= 0
					dpw[j] = [dpw[j],dp[k] + (c[k] - c[j]).abs].max
				end
			end
		else
			dpw[j] = -1
		end
	end
	for j in 0...n
		dp[j] = dpw[j]
	end
end
all = 0
for i in 0...n
	all = [all, dp[i]].max
end
print(all,"\n")