
object Main extends App {

  import scala.io.StdIn._

  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val plan = readLine.trim.split(' ').map(_.toInt - 1)
  val stations = Array.tabulate(n - 1){_ ⇒
    val Array(a, b, c) = readLine.trim.split(' ').map(_.toInt)
    Town(a, b, c)
  }
  val times = Array.tabulate(n){_ ⇒ 0}
  for (p ← 1 until m){
    if (plan(p - 1) < plan(p)) {
      times(plan(p - 1)) += 1
      times(plan(p)) -= 1
    }else {
      times(plan(p)) += 1
      times(plan(p - 1)) -= 1
    }
  }
  for (t ← 1 until n){
    times(t) += times(t - 1)
  }
  println(
    times.dropRight(1).zip(stations).map{
      case (time, Town(a, b, c)) ⇒
        if (a * time < c + b * time) a * time
        else c + b * time
    }.sum
  )


  case class Town(a: Long, b: Long, c: Long)

  implicit class ScopeFunc[T](val value: T) {
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}

/*
 */
