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 ->
      acc ++ [(IO.gets("") |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1))]
    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
    [_ | tail] = List.zip(list_of_lists)
    tail
    |> 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
    [head | _] = List.zip(list_of_lists)
    head |> Tuple.to_list() |> Enum.sum()
  end

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

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