#$stdin = File.open("test.txt","r")


(N,M) = gets.split(" ").map{|s| s.to_i }
P = gets.split(" ").map{|s| s.to_i - 1 }
A = []
B = []
C = []
while lines = gets
  ary = lines.split(" ").map{|s| s.to_i}
  A.push( ary[0])
  B.push( ary[1])
  C.push( ary[2])
end

# p "P",P
# print("A",A)
# print("B",B)
# print("C",C)
throw = Array.new(N - 1 , 0)
# p throw#

(M-1).times do |i|
  #print i
  a = [ P[i] , P[i+1] ].min
  b = [ P[i] , P[i+1] ].max
  #print("a",a,"b",b)
  Range.new(a,b-1).step(1){|p|
    #print(i,"/",p,",")
    throw[p] += 1
  }
end
# p "aaa"
p Range.new(0,(N-1)).inject{|memo,i|
  i = i-1
  #p [A[i] * throw[i] , B[i] * throw[i] + C[i]]
  [A[i] * throw[i] , B[i] * throw[i] + C[i]].min + memo
}

# p throw.zip(A,B,C).inject{|memo,i|
#   p memo
#   [i[1] * i[0] , i[2] * i[0] + i[3]].min + memo
# }