Sangbeom's Picture Frame

Time limit2sMemory limit64 MB

Problem

Sangbeom wants to build a picture frame out of a metal structure. The structure is made of several iron rods soldered together at beads, like the figure below.

The frame he wants must be a single closed loop made only of rods: every rod must be joined one after another into a single loop. To achieve this, Sangbeom may use two kinds of actions.

  • Remove a bead: take out one bead. While doing so, he may regroup the rods that were soldered at that bead however he likes — he can keep some rods soldered together in groups and separate the others. This whole regrouping counts as a single action.
  • Join two rods: solder together two rod ends that are currently free (attached to nothing). This is also a single action.

For example, to turn the structure above into a frame he could do the following. Remove bead A, separating rod 1. Remove bead D, separating the pair of rods 4-5 and the pair 3-7 while keeping each pair soldered together. Remove bead E, separating rod 7. Finally, join the still-free ends of rod 1 and rod 7. This completes a single loop in the order 1-7-3-2-4-5-6-8 — the frame.

Sangbeom wants to move as little as possible. Given the initial state of the metal structure, find the minimum number of actions needed to complete the frame.

Input

The first line contains the number of beads $N$ ($0 \le N \le 1000$) and the number of rods $M$ ($2 \le M \le 50,000$).

Beads are numbered from $1$ to $N$. Each of the next $M$ lines contains two integers describing which beads the two ends of one rod are attached to. An end that is not attached to any bead is written as $0$.

The structure may consist of several disconnected pieces (that is, it need not be connected initially). A bead may have only one rod attached to it; such a bead need not be removed before its rod is joined to another. Some beads may have no rods attached at all; since Sangbeom cares only about the rods, such beads may be removed or left in place freely.

Output

Print a single integer: the minimum number of actions needed to complete the frame.