defmodule Main do def main do n = IO.read(:line) |> String.trim() |> String.to_integer() IO.read(:line) |> String.trim() |> String.to_integer() |> (&(1..&1)).() |> Enum.map(fn _ -> IO.read(:line) |> String.split() |> Enum.map(&String.to_integer/1) end) |> solve(n) |> IO.puts() end defp solve(pq, n) do cond do Enum.empty?(pq) -> n true -> [p, q] = hd(pq) Enum.slice(pq, 1..-1) |> solve( cond do p == n -> q q == n -> p true -> n end ) end end end