There are dominoes arranged in a peculiar order labeled from to .
Some dominoes knock down other dominoes when they are knocked down.
It is possible to knock down an entire chain of dominoes by knocking down a single one.
You are given a list of pairs in the form a b
, where domino a
will knock down domino b
when knocked down.
Determine the minimum number of dominoes you need to knock down manually in order to knock down all of them.
Constraints
Input Specification
The first line of input contains space-separated integers and .
The next lines of input each contain space-separated integers and .
Output Specification
Output a single integer, the minimum number of dominoes you need to knock down manually.
Sample Input 1
4 3
2 3
3 4
4 1
Sample Output 1
1
Explanation for Sample 1
It is optimal to knock down domino , which will result in the following chain: .
Sample Input 2
5 4
3 4
2 3
2 1
1 2
Sample Output 2
2
Explanation for Sample 2
Knocking down domino will knock down dominoes , , and .
Domino needs to be knocked down separately.
Comments
This comment is hidden due to too much negative feedback. Click here to view it.