Strong connectivity#2403

Strong connectivity

1 second
128 megabytes
Medium

A strongly connected component in a directed graph is a maximal set of vertices such that for every pair of vertices and in the set, there is a path from to and from to .

Given a directed graph, find the number of strongly connected components in it.

Input

The first line contains two integers and (1 \leq n \leq 10, 0 \leq m \leq 90) — the number of vertices and edges in the graph, respectively.

Each of the next lines contains two integers u_i and v_i (1 \leq u_i, v_i \leq n), describing a directed edge from vertex u_i to vertex v_i.

It is guaranteed that the graph contains no loops (edges from a vertex to itself) and no multiple edges (edges with the same start and end).

Output

Print one integer — the number of strongly connected components in the given graph.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading