Road Construction

Interview

Time limit1sMemory limit128 MB

Summary
Given a connected undirected graph, add the fewest edges so that deleting any single edge still leaves the graph connected.
Level

Medium7 of 10

Topics
Graph, DFS, Greedy, Implementation
Solved
No attempts yet

Problem

It's almost summer, which means it's almost time for summer road construction! This year, the people in charge of the roads on the tropical island paradise of Remote Island want to repair and upgrade the various roads that lead between the tourist attractions on the island.

The roads themselves are rather interesting. Because of the island's unusual customs, the roads never meet at intersections; instead they pass over or under one another using bridges and tunnels. In this way each road runs directly between two specific tourist attractions, so that tourists never become hopelessly lost.

Unfortunately, given the nature of the repairs and upgrades, whenever the construction company works on a particular road, that road is unusable in both directions. This can be a problem if it makes it impossible to travel between two attractions, even though the company works on only one road at a time.

To prevent this, the road department has decided that new roads must be built so that, in the final configuration, if any single road is under construction it is still possible to travel between any two attractions using the remaining roads. Your task is to find the minimum number of new roads that must be built.

Input

The first line contains two positive integers nn and rr separated by a space, where 3≤n≤10003 \le n \le 1000 is the number of tourist attractions on the island and 2≤r≤10002 \le r \le 1000 is the number of roads. The attractions are labelled from 11 to nn.

Each of the next rr lines contains two integers vv and ww separated by a space, indicating that a road connects the attractions labelled vv and ww. Each road may be travelled in either direction, and any pair of attractions is directly connected by at most one road. You are guaranteed that, in the current configuration, it is possible to travel between any two attractions.

Output

Output a single line containing one integer: the minimum number of roads that must be added.

Examples2

  1. Example 1

    Input
    10 12
    1 2
    1 3
    1 4
    2 5
    2 6
    5 6
    3 7
    3 8
    7 8
    4 9
    4 10
    9 10
    
    Expected output
    2
    
  2. Example 2

    Input
    3 3
    1 2
    2 3
    1 3
    
    Expected output
    0