defmodule Main do def main do beans_sum = IO.gets("") |> String.trim |> String.split |> Enum.take(2) |> Enum.map(&String.to_integer/1) |> sum(1) age_sum = IO.gets("") |> String.trim |> String.split |> Enum.map(&String.to_integer/1) |> Enum.sum out(beans_sum, age_sum) end def sum([], acc) do acc end def sum([head|tail], acc) do sum(tail, acc*head) end def out(beans_sum, age_sum) when beans_sum >= age_sum do IO.puts beans_sum-age_sum end def out(_, _) do IO.puts -1 end end