import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Array.Unboxed

main :: IO ()
main = do
  [n,m] <- getl $ wrds toInt
  solve n <$> (getl $ wrds toInt) <*> replicateM (n-1) (getl $ wrds toInt) >>= print

solve :: Int -> [Int] -> [[Int]] -> Int
solve n ps rs = sum $ map g $ assocs ar
  where
    ls = concat $ map f $ zip ps (tail ps)
    f (p,q)
      | p < q = [p..q-1]
      | otherwise = [q..p-1]
    ar = accumArray (+) 0 (1,n-1) [(i,1) | i <- ls] :: UArray Int Int
    g (s,i) = min (rs !! (s-1) !! 0 * i) (rs !! (s-1) !! 1 * i + rs !! (s-1) !! 2)
                    
toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine