N, M = gets.split.map &:to_i
P = gets.split.map &:to_i
A, B, C = (N - 1).times.map{gets.split.map &:to_i}.transpose.map{|a| [nil] + a}
p P.each_cons(2).with_object(Hash.new{|h, k| h[k] = 0}){|(p, c), h| p.upto(c - 1){|i| h[i] += 1}; (p-1).downto(c){|i| h[i] += 1}}.map{|k, v| [A[k] * v, B[k] * v + C[k]].min}.inject(:+)