You are given an undirected graph with vertices and edges. The vertices are numbered .
Two vertices are connected if it is possible to start from and reach by moving along edges zero or more times. In particular, every vertex is connected to itself.
You want to add some new undirected edges so that every pair of vertices is connected. Find the minimum number of edges that must be added.
Input
The input is given in the following format.
For each (), this means that there is an undirected edge between and .
Output
Print the minimum number of edges that must be added.
Constraints
- .
- .
- ().
- ().
- Considering and as the same edge, no edge appears more than once in the input.
Subtasks
Samples
The initial graph has two connected components: and . Adding one edge between the two components makes all vertices connected.
There are no edges, so each of the vertices is its own connected component. Therefore, edges are necessary.
All vertices are already connected, so no edge needs to be added.