SP20986 UCBINTH - Hypertubes

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 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.