Yan enjoys travelling around the country of Iatiland in his car.
Since Yan has been travelling for a long time, he has come up with a description of the map of the whole country. The cities in Iatiland are numbered from to , and there are bi-directional direct roads connecting pairs of different cities. For each city, he has a list of cities that are reachable from it using a direct road. It is guaranteed, that there is a unique path between every pair of cities. Note that the path may not be direct, i.e. it may use several direct roads. Notice that this means that there are a total of direct roads.
Yan likes travelling systematically, so he came up with an algorithm he will follow whilst going around the country.
He starts his journey in city on day and every subsequent day he will follow a direct road from the city he is currently in.
The road he chooses is always the first road in the list of the current city.
However, this simple procedure seemed pretty boring to Yan, so after picking the road he will next travel on, he removes it from the beginning of the list and appends it to the end.
Yan's main objective for travelling is to meet his friends and gossip with them.
He has friends he wants to visit, numbered from to and each friend lives in the city . He can visit friend only when he is currently in city . Additionally, Yan wants to visit his friends in the given order, i.e. he cannot visit friend before visitng friend .
Task
Help Yan find the minimal number of days before he visits all of his friends in the correct order.
Input data
The first line of the standard input contains numbers - and .
This is followed by lines, where on line , there are given - the number of direct paths coming out of city , followed by numbers - the initial list of cities to which city is connected by a direct path.
Following are numbers on one line - , the cities where Yan's friends live.
Output data
Output the required minimum number of days on a single line on the standard output.
Constraints and clarifications
# | Score | Constraints |
---|---|---|
1 | 10 | , |
2 | 10 | , |
3 | 20 | , |
4 | 10 | , |
5 | 15 | , , |
6 | 20 | , |
7 | 15 | , |
Example
stdin
4 4
2 2 3
1 1
2 1 4
1 3
2 1 1 4
stdout
9
Explanation
Yan’s journey will take days to pass through the cities in that sequence.
He will meet friend on the second day, friend on the third day, friend on the fifth day, and friend on the ninth day.