#Q113. 「一本通 3.7 练习 5」相框
「一本通 3.7 练习 5」相框
Description
Original Source: Fujian Training Camp 2011
The basic circuit lab at P University is an extremely boring class. Every time during the lab, T-kun finishes early, but the administrator won't let him leave, leaving T-kun with nothing to do but sit there idly.
To describe the lab, it's simply about soldering a few wires and some components (resistors, capacitors, inductors, etc.) together.
To pass the time, T-kun has been soldering some bizarre creations after each lab session. Here's one of his masterpieces:

Not satisfied with just welding odd-shaped creations, a strong destructive urge drives him to dismantle this piece and then solder it into a more regular shape. This time, T-kun wants to transform this monstrosity into a ring to use as a photo frame, following these steps:

T-kun defines two operations:
-
Melt a solder joint: This separates or keeps connected certain wires attached to the joint (can be understood as dividing the wires at the joint into several groups, where wires in the same group remain connected, and those in different groups become separated).
-
Solder two free ends of wires together: Free ends refer to wire ends that are not connected to any other wire.
For example, in the steps above, first melt joint to separate wire from wires ; then melt joint to separate from ; next melt to separate from ; finally, connect and .
T-kun wants to use the minimum number of operations to transform the original creation into a photo frame (using all the wires).
Input Format
The first line contains two integers and —the number of solder joints and wires in the original creation, respectively. The solder joints are labeled from to . The next lines each contain two integers—the labels of the two solder joints connected by a wire. If a wire end is not connected to any joint, it is labeled as .
The original creation may not be connected.
Some solder joints may have only one wire connected to them. These joints cannot be melted until the free end of that wire is connected to another wire.
Some solder joints may have no wires connected to them at all. Since T-kun only cares about the wires, these joints can be ignored.
Output Format
Output a single integer—the minimum number of steps T-kun needs to transform the original creation into a photo frame.
Sample 1
6 8
1 2
1 3
3 4
1 4
4 6
5 6
4 5
1 5
4
Data Range and Hints
of the data has ;
of the data has .