-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

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

solve (n:x:a) = ans where
    sm = sum a
    mn = minimum a
    (h, t) = span ((mn + x) <) a
    xs = t ++ h
    (r, s, c) = foldl (\(r, s, c) k -> if k >= (x + mn) then (r, s + 1, c) else (maximum [r, s], 0, c + k)) (0, 0, 0) xs
    m = maximum [r, s]
    xx =  m * mn + x * m + c
    ans = minimum [sm, xx]
