-- AtCoder My Practice
-- author: Leonardone @ NEETSDKASU
 
-- 解説読後
-- http://agc004.contest.atcoder.jp/data/agc/004/editorial.pdf

import qualified Data.ByteString.Char8 as C
import Data.Array (listArray, accumArray, (!))
 
main = print . solve . fmap red . C.words =<< C.getContents
    where
        red x = case C.readInteger x of Just v -> fst v

solve (n:x:a) = ans where
    ans = f (n - 1) (sum a) a x
    f 0 r _ _ = r
    f c r ar xx = f (c - 1) r2 ar2 (xx + x) where
        ar2 = zipWith min a $ [last ar] ++ ar
        r2 = min r (xx + sum ar2)
