Informikas is creating a website. He has gathered a great amount of information, come up with a beautiful design and optimized the page for best user experience.
To make the structure of the webpage simple, Informikas abides to simple rules:
However, not everything is flawless. After showing his website to friends he have found out that people, who browse the Internet on their mobile phones, are very lazy:
Links and "back" button works as in every browser:
Informikas would like to know, what is the maximum number of pages a mobile user could view before getting annoyed. Having the list of webpages with links inside them and the count of times a user has to see the same page to get annoyed, find that number.
In the first line of input there are two integers N and K (1 ≤ N ≤ 105, 1 ≤ K ≤ 105) – the number of webpages and the number of times mobile user could see the same page before getting annoyed. The pages are numbered from 1 to N. Every following N lines consist of integer Mi (0 ≤ Mi, 1 ≤ i ≤ N) – the number of links inside the page i – followed by Mi integers Qi, j (1 ≤ Qi, j ≤ N,) – the names of pages, meaning that page i has a link to page Qi, j.
The homepage (the page mobile user starts browsing the website) has the index 1 (the page described on the second line of input).
Output single integer, equal to the maximum number of pages mobile user could see before getting annoyed.
3 1
2 2 3
0
0
2
3 2
2 2 3
0
0
3
8 2
3 2 3 4
2 5 7
0
0
1 6
0
1 8
0
7
In the first test case, user enters the home page and then clicks a link to one of the other two pages (either 2 or 3). Any of the two pages have no links. Now, by pressing "back" button, mobile user would reopen homepage, get annoyed and leave. This gives an answer of 2.
In the second test case mobile user could go 1 > 2 < 1 > 3 (here > means clicking the link and < means pressing back button). This results in 3 viewed pages.
In the third test case one of possible paths would be 1 > 3 < 1 > 2 > 5 > 6 < 5 < 2 > 7 > 8. This results in 7 viewed pages (1, 2, 3, 5, 6, 7, 8).