let rec tabulate n f = 
  let rec loop acc m =
    if m < n then loop (f m :: acc) (m + 1)
    else List.rev acc in
  loop [] 0

let () =
  let n, x = Scanf.scanf "%d %d\n" (fun n x -> n, x) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  tabulate n (fun magics -> magics)
  |> List.fold_left (fun (acc, times) magics ->
      (List.fold_left ( + ) (x * magics) times :: acc,
       let magics = magics + 1 in
       List.mapi (fun i time -> min time as_.((n + i - magics) mod n)) times))
      ([], tabulate n (fun i -> as_.(i)))
  |> fst
  |> List.fold_left min max_int
  |> Printf.printf "%d\n"
