n, m = gets.split.map(&:to_i)
cnt = Array.new(n-1, 0)
l = gets.split.map(&:to_i)
l.each_cons(2){|arr| eval(arr.sort * "...").each{|i| cnt[i-1] += 1}}
sum = 0
(n-1).times do |i|
  a, b, c = gets.split.map(&:to_i)
  (a-b)*cnt[i] < c ? (sum += a*cnt[i]) : (sum += b*cnt[i]+c)
end
p sum