Under construction

Still being built. Things may change

Pitch-Black Room

Time limit2sMemory limit512 MB

Summary
Find the shortest fixed sequence of edge choices that leads every starting room to a bright room, regardless of where A starts.
Level

Hard8 of 10

Topics
Graph, Bit manipulation, BFS, Dynamic programming
Solved
No attempts yet

Problem

A wakes up inside a pitch-black room. He seems to have wandered into a dungeon made of NN rooms. You could not find out which room A is in, but luckily you got hold of the dungeon map. Point out the path A should take and lead him to a bright room.

Of the NN rooms, MM are pitch-black, and you know that rooms D1D_1, D2D_2, ......, DMD_M are the pitch-black ones. Also, every room has exactly KK one-way paths laid out in order, and the paths leaving room ii lead to rooms vi,1v_{i,1}, vi,2v_{i,2}, ..., vi,Kv_{i,K}. You can make A take the a1a_1-th, a2a_2-th, ..., ala_l-th paths in order from the room he is in. Once A reaches a bright room, he ignores all further instructions. You cannot know which room A is in, neither before nor after giving instructions, so the sequence of instructions you pass on must lead A to a bright room no matter which room he started in.

Among such instruction sequences, find the length of the shortest one.

Input

The input is given from standard input in the following format.

NN MM KK

D1D_1 D2D_2 ...... DMD_M

v1,1v_{1,1} v1,2v_{1,2} ...... v1,Kv_{1,K}

v2,1v_{2,1} v2,2v_{2,2} ...... v2,Kv_{2,K}

......

vN,1v_{N,1} vN,2v_{N,2} ...... vN,Kv_{N,K}

Output

Print the answer on one line.

Constraints

  • 2≤N≤1002 \leq N \leq 100
  • 1≤M≤min(16,N−1)1 \leq M \leq min(16, N-1)
  • 1≤K≤N1 \leq K \leq N
  • 1≤Di≤N1 \leq D_i \leq N
  • All DiD_i are distinct
  • 1≤vi,j≤N1 \leq v_{i, j} \leq N
  • Every dark room can reach at least one bright room

Examples3

  1. Example 1

    Input
    4 2 2
    1 2
    2 4
    3 1
    4 2
    1 3
    
    Expected output
    2
    
  2. Example 2

    Input
    3 2 2
    1 2
    2 3
    1 2
    2 1
    
    Expected output
    3
    
  3. Example 3

    Input
    6 3 3
    1 2 3
    4 1 1
    2 5 2
    3 3 6
    4 4 4
    5 5 5
    6 6 6
    
    Expected output
    3