let [| N; K |] = stdin.ReadLine().Split() |> Array.map int
stdin.ReadLine().Split() |> Array.map int
|> Array.pairwise
|> Array.map (fun (x, y) -> y - x)
|> fun x -> Array.append x [| x.[0] + N - x.[K - 1] |]
|> fun x -> (x |> Array.sum) - (x |> Array.max)
|> printfn "%d"
