IntermediateRating 1300
Cables Needed to Connect
n computers and m cables (a cable joins two computers). You may unplug any cable and re-plug it between any two computers. Print the fewest moves to connect all computers, or -1 if there aren't enough cables.
Input
n and m; then m lines 'u v'.
Output
One integer.
Sample 1
Input
4 3 1 2 1 3 2 3
Output
1
Sample 2
Input
6 5 1 2 1 3 1 4 2 3 2 4
Output
2
Output appears here