-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

main = print . solve . map read . words =<< getContents

solve (n:x:a) = ans where
    sm = sum a
    mn = minimum a
    (hs, ts) = span (mn <) $ reverse a
    xs = ts ++ hs
    (y:ys) = xs
    (r, c, z) = foldl (\(r, c, z) k -> if k > (z + x) then (r, c + 1, z) else (r + (z + x) * c + k, 0, k)) (y, 0, y) ys
    xx = r + (z + x) * c
    ans = minimum [sm, xx]
