#P1253D. Harmonious Graph
Harmonious Graph
Description
You're given an undirected graph with nodes and edges. Nodes are numbered from to .
The graph is considered harmonious if and only if the following property holds:
- For every triple of integers such that , if there exists a path going from node to node , then there exists a path going from node to node .
In other words, in a harmonious graph, if from a node we can reach a node through edges (), then we should able to reach nodes too.
What is the minimum number of edges we need to add to make the graph harmonious?
The first line contains two integers and ( and ).
The -th of the next lines contains two integers and (, ), that mean that there's an edge between nodes and .
It is guaranteed that the given graph is simple (there is no self-loop, and there is at most one edge between every pair of nodes).
Print the minimum number of edges we have to add to the graph to make it harmonious.
Input
The first line contains two integers and ( and ).
The -th of the next lines contains two integers and (, ), that mean that there's an edge between nodes and .
It is guaranteed that the given graph is simple (there is no self-loop, and there is at most one edge between every pair of nodes).
Output
Print the minimum number of edges we have to add to the graph to make it harmonious.
Note
In the first example, the given graph is not harmonious (for instance, , node can reach node through the path , but node can't reach node ). However adding the edge is sufficient to make it harmonious.
In the second example, the given graph is already harmonious.