defmodule Main do def shuffle(cards, []), do: cards def shuffle(cards, orders) do [n | orders] = orders cards = cards |> List.pop_at(n - 1) |> (fn {x, y} -> [x] ++ y end).() shuffle(cards, orders) end def main do inputs = IO.binread(:all) |> String.split [n, _ | as] = inputs |> Enum.map(&String.to_integer/1) IO.puts shuffle(Enum.to_list(1..n), as) |> List.first end end