Under construction

Still being built. Things may change

The Restless Cat

Time limit2sMemory limit512 MB

Summary
In a connected, planar, simple graph with a guaranteed cycle, find rooms whose single-vertex deletion leaves the graph acyclic (a forest), summing their indices.
Level

Hard8 of 10

Topics
Graph, DFS, Implementation
Solved
No attempts yet

Problem

Cheolmin keeps a cat. He built a multi-level playground for it, and the playground has NN rooms and MM corridors. The rooms are numbered 1 through NN. Each corridor joins two different rooms and can be walked in both directions. At most one corridor joins any given pair of rooms. Every room is reachable from every other room along corridors. The playground is built in three dimensions, so no two corridors cross. The picture below shows a playground with 4 rooms and 5 corridors.

A playground with 4 rooms and 5 corridors

The cat is very restless and runs around the playground without stopping. It likes to pick kk distinct rooms (k≥3)(k \ge 3), fix an order (a1,a2,…,ak)(a_1, a_2, \ldots, a_k), and then run through that order again and again, so it visits a1,a2,…,ak,a1,a2,…,ak,a1,…a_1, a_2, \ldots, a_k, a_1, a_2, \ldots, a_k, a_1, \ldots in turn. For such a run, a1a_1 and a2a_2, a2a_2 and a3a_3, ..., aka_k and a1a_1 must each be joined by a corridor.

Cheolmin worries that the cat tires itself out, so he wants to leave no repeating run at all. To keep the work small, he removes exactly one room and closes the corridors attached to it.

In the playground above the cat can run rooms 1, 2, 3 in that order, and it can also run rooms 1, 2, 4, 3 in that order. Removing room 2 leaves no repeating run. Removing room 3 gives the same result. Removing room 4 still leaves a repeating run.

You are given the rooms and the corridors. Find the number of a room whose removal destroys every repeating run. If several rooms work, find the sum of their numbers. If no room works, the answer is 0.

Input

The first line contains the number of rooms NN and the number of corridors MM, separated by a space. (2≤N≤300 000(2 \le N \le 300\,000, 1≤M≤300 000)1 \le M \le 300\,000)

Each of the next MM lines contains the numbers of the two different rooms joined by one corridor. No pair of rooms appears more than once. The given playground has at least one repeating run.

Output

If removing a single room destroys every repeating run, print the number of that room. If several rooms work, print the sum of their numbers. If no room works, print 0.

Note

In the first example, removing room 2 works and removing room 3 works, so the answer is the sum 5.

Examples3

  1. Example 1

    Input
    4 5
    1 2
    2 3
    4 2
    4 3
    3 1
    
    Expected output
    5
    
  2. Example 2

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

    Input
    8 10
    1 2
    2 3
    3 4
    4 5
    5 6
    6 7
    7 8
    8 1
    2 7
    3 6
    
    Expected output
    0