class Array
	def accum
		inject([0]){|a, x| a + [a[-1] + x]}
	end

	def accum!
		(1..size-1).each{|i|
			self[i] += self[i-1]
		}
		self.unshift(0)
	end

	def accum_2d
		ac = map{|r| r.accum}
		(1..size-1).each{|i|
			(1..ac[0].size-1).each{|j|
				ac[i][j] += ac[i-1][j]
			}
		}
		ac.unshift([0] * ac[0].size)
		ac
	end

	def accum_2d!
		each{|r| r.accum!}
		(1..size-1).each{|i|
			(1..self[0].size-1).each{|j|
				self[i][j] += self[i-1][j]
			}
		}
		unshift([0] * self[0].size)
	end
		
	def bsearch_first_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_first_index(l, c-1, &pred) || c
		else
			bsearch_first_index(c+1, r, &pred)
		end
	end

	def bsearch_first_item(l = 0, r = size - 1, &pred)
		i = bsearch_first_index(l, r, &pred)
		i ? self[i] : nil
	end

	def bsearch_last_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_last_index(c+1, r, &pred) || c
		else
			bsearch_last_index(l, c-1, &pred)
		end
	end

	def bsearch_last_item(l = 0, r = size - 1, &pred)
		i = bsearch_last_index(l, r, &pred)
		i ? self[i] : nil
	end
end

class IntervalTree
	def initialize(l, r)
		@l = l
		@r = r
		@c = (l + r) / 2
		@left_child = @right_child = nil
		@start_sorted = []
		@end_sorted = []
	end

	def add(l, r, x)
		if r < @c
			@left_child ||= self.class.new(l, @c - 1)
			@left_child.add(l, r, x)
		elsif @c < l
			@right_child ||= self.class.new(@c + 1, r)
			@right_child.add(l, r, x)
		else
			i = @start_sorted.bsearch_first_index{|p, q, _| p >= l} || @start_sorted.size
			@start_sorted.insert(i, [l, r, x])
			i = @end_sorted.bsearch_first_index{|p, q, _| q >= r} || @end_sorted.size
			@end_sorted.insert(i, [l, r, x])
		end
	end

	def query(x)
		if x < @c
			ans = @start_sorted.take_while{|l, r| l <= x} 
			ans += @left_child.query(x) if @left_child
			ans
		elsif x > @c
			ans = []
			ans += @right_child.query(x) if @right_child
			i = @end_sorted.bsearch_first_index{|l, r| x <= r}
			ans += @end_sorted[i..-1] if i
			ans
		else
			@start_sorted
		end
	end
end

d, n = gets.split.map &:to_i
temp = (1..d).map{ gets.to_i }

t = IntervalTree.new(0, 60)

n.times {
	a, b, c = gets.split.map &:to_i
	t.add(a, b, c)
}

hash1 = Hash.new(0)
t.query(temp[0]).each{|_, _, c|
	hash1[c] = 0
}
temp.shift

temp.each{|x|
	hash2 = Hash.new(0)
	cloths = t.query(x)
	hash1.each{|c1, v1|
		cloths.each{|_, _, c2|
			value = v1 + (c1 - c2).abs
			hash2[c2] = value if value > hash2[c2]
		}
	}
	hash1 = hash2
}
p hash1.values.max