let N = stdin.ReadLine().Split(' ').[0] |> int let ss = stdin.ReadLine().Split(' ') |> Seq.map int |> Seq.toList let rec ml i p l = function | x::xs -> ml i (p+1) (if i = p then x::l else l@[x]) xs | _ -> l let rec f c = function | s::ss -> if s = 1 then f c ss else f (ml s 1 [] c) ss | _ -> c.[0] f [1..N] ss |> printfn "%d"