require 'set'

def bfs(start_node, extra = nil)
    return 0 if start_node.is_goal?(extra)
    reached = Set[start_node]
    dist = 1
    queue = [start_node]
    until queue.empty?
        next_queue = []
        until queue.empty?
            node = queue.shift
            node.each_next_node(extra) do |next_node|
                return dist if next_node.is_goal?(extra)
                next if reached.include?(next_node)
                reached << next_node
                next_queue << next_node
            end
        end
        dist += 1
        queue = next_queue
    end
    return nil
end

n, m, k = gets.split.map(&:to_i)

dark_rooms = 0
gets.split.map(&:to_i).each do |i|
    dark_rooms |= (1 << i)
end

neighbour = Hash.new(0)
(1..n).each do |i|
    neighbour[i] = [0] + gets.split.map(&:to_i)
    neighbour[i].map! {|x| 1 << x}
end

class Integer
    def is_goal?(extra)
        self == 0
    end

    def each_next_node(extra)
        n = extra[:n]
        k = extra[:k]
        dark_rooms = extra[:dark_rooms]
        neighbour = extra[:neighbour]

        a = Array.new(k + 1, 0)
        (1..n).each do |j|
            next if self[j] == 0
            (1..k).each do |i|
                a[i] |= neighbour[j][i]
            end
        end
        a[1..-1].each do |y|
            yield y & dark_rooms
        end
    end
end

extra = {
    :k => k,
    :n => n,
    :dark_rooms => dark_rooms,
    :neighbour => neighbour,
}
p bfs(dark_rooms, extra)

