P7646 [COCI 2012/2013 #5] HIPERCIJEVI
Description
In a galaxy far, far away, the fastest method of transportation is using hypertubes. Each hypertube directly connects $K$ stations with each other. What is the minimum number of stations that we need to pass through in order to get from station $1$ to station $N$?
Input Format
The first line of input contains three positive integers: $N$ ( $1 \le N \le 100000$ ), the number of stations, $K$ ( $1 \le K \le 1000$ ), the number of stations that any single hypertube directly interconnects, and $M$ ( $1 \le M \le 1000$ ), the number of hypertubes.
Each of the following $M$ lines contains the description of a single hypertube: $K$ positive integers, the labels of stations connected to that hypertube.
Output Format
The first and only line of output must contain the required minimum number of stations. If it isn't possible to travel from station $1$ to station $N$, output $-1$.
Explanation/Hint
Clarification of the first example: It is possible to travel from station $1$ to station $9$ using only four stations in the following ways: $1$-$3$-$6$-$9$, or $1$-$5$-$6$-$9$.
Source:[COCI2012~2013](https://hsin.hr/coci/archive/2012_2013/) [CONTEST#5](https://hsin.hr/coci/archive/2012_2013/contest5_tasks.pdf) _**T4 HIPERCIJEVI**_