defmodule Main do
  def main do
    [n, _m, x] =
      IO.gets("") |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1)

    list =
      Enum.reduce(1..n, [], fn _, acc ->
        [IO.gets("") |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1)] ++
          acc
      end)

    Enum.reduce(1..n, [], fn i, acc ->
      combination(list, i) ++ acc
    end)
    |> Enum.filter(&_filter(&1, x))
    |> Enum.map(&_sum/1)
    |> Enum.min(fn -> -1 end)
    |> IO.puts()
  end

  defp _filter(list_of_lists, x) do
    List.zip(list_of_lists)
    |> tl()
    |> Enum.map(fn tuple ->
      tuple |> Tuple.to_list() |> Enum.sum()
    end)
    |> Enum.all?(fn sum -> sum >= x end)
  end

  defp _sum(list_of_lists) do
    List.zip(list_of_lists) |> hd() |> Tuple.to_list() |> Enum.sum()
  end

  defp combination(_, 0), do: [[]]
  defp combination([], _), do: []

  defp combination([x | xs], n) do
    for(y <- combination(xs, n - 1), do: [x | y]) ++ combination(xs, n)
  end
end