class LinearLazySegmentTree
	def initialize(a, l = 1, r = a.size)
		@range_min = l
		@range_max = r
		@n = r - l + 1
		@a = 1
		@b = 0
		if l == r
			@sum = a[l-1]
		else
			c = (l + r) / 2
			@left_child = self.class.new(a, l, c)
			@right_child = self.class.new(a, c+1, r)
			@sum = @left_child.sum(l,c) + @right_child.sum(c+1,r)
		end
	end

	attr_reader :range_min, :range_max

	def operate(x, y, a1, b1)
		return 0 if x > y

		if x == @range_min && y == @range_max
			s = @a * @sum + @n * @b
			@a, @b = @a * a1,  (a1 * @b + b1)
			(a1 * s + @n * b1 - s)
		else
			force
			lr = @left_child.range_max
			addition = @left_child.operate(x, lr < y ? lr : y, a1, b1)
			rl = @right_child.range_min
			addition += @right_child.operate(rl > x ? rl : x, y, a1, b1)
			@sum = (@sum + addition)
			addition
		end
	end

	def add(x, y, v)
		operate(x, y, 1, v)
	end

	def sub(x, y, v)
		operate(x, y, 1, -v)
	end

	def mul(x, y, v)
		operate(x, y, v, 0)
	end

	def const(x, y, v)
		operate(x, y, 0, v)
	end

	def force
		if @range_min != @range_max
			@left_child.delegate(@a, @b)
			@right_child.delegate(@a, @b)
		end
		@sum = (@a * @sum + @n * @b)
		@a = 1
		@b = 0
	end

	def delegate(a, b)
		@a = @a * a  
		@b =  (a * @b + b)
	end

	def sum(x, y)
		return 0 if x > y

		if x == @range_min && y == @range_max
			(@a * @sum + @n * @b)
		else
			force
			lr = @left_child.range_max
			sum = @left_child.sum(x, lr < y ? lr : y)
			rl = @right_child.range_min
			sum += @right_child.sum(rl > x ? rl : x, y)
			sum
		end
	end
end

n, m = gets.split.map(&:to_i)
llst = LinearLazySegmentTree.new([0] * (n-1))

route = gets.split.map(&:to_i)
route.each_cons(2){|i, j|
	i, j = j, i if i > j
	llst.add(i, j-1, 1)
}

min_cost = 0
(1..n-1).each{|i|
	a, b, c = gets.split.map(&:to_i)	
	k = llst.sum(i, i)
	min_cost += [a * k, b * k + c].min
}
p min_cost