A change-notification system models n components. A directed edge u v means a change in u triggers a re-evaluation of v. When component 0 changes, the trigger cascades along directed edges. Count how many distinct components (other than 0 itself) are eventually re-evaluated. The graph may contain cycles; each reachable component is counted once.
Input format
Line 1: two integers n and m — the number of nodes (labeled 0 through n-1) and the number of directed edges.
Each of the next m lines: two integers u v, a directed edge from to (read as: must come before ).
Output format
A single integer: the number of distinct nodes reachable from node 0, excluding node 0.
Constraints
- 1 <= n <= 30
- 0 <= m <= 200
- 0 <= u, v <= n-1 (cycles and self-loops may appear)