#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:

1.jpg

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:

2.jpg

T-kun defines two operations:

  1. 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).

  2. 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 AA to separate wire 11 from wires 2,42,4; then melt joint DD to separate 4,54,5 from 3,73,7; next melt EE to separate 77 from 6,86,8; finally, connect 11 and 77.

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 nn and mm—the number of solder joints and wires in the original creation, respectively. The solder joints are labeled from 11 to nn. The next mm 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 00.

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

30%30\% of the data has n10n \le 10;
100%100\% of the data has 0n1000,2m500000 \le n \le 1000, 2 \le m \le 50000.