Under construction

Still being built. Things may change

Counter-manifestation

Time limit3.5sMemory limit256 MB

Summary
Given a directed road graph, check whether it contains a cycle, and list every junction that all cycles must pass through.
Level

Medium7 of 10

Topics
Graph, DFS, Divide and conquer
Solved
No attempts yet

Problem

As every year, The P=NPP=\mathit{NP} Equality Parade takes place in Bytebury. It is an event during which individuals sharing a belief that for each language LL, for which there exists a non-deterministic Turing machine recognizing LL in a polynomial number of steps, there is also a deterministic Turing machine that recognizes the language in a polynomial number of steps, manifest their views publicly.

Previous editions of the parade proceeded peacefully: participants shouted "3-SAT is easy!" at most or raised banners presenting pseudo-code of the latest polynomial "algorithms" for finding the Hamiltonian cycle. However, this drew little interest from passers-by. This year, the parade organizers have decided to focus the attention of Bytebury residents and plan to chant more shocking slogans (which are somewhat true if P=NPP=\mathit{NP}), including "Our money is not safe!" and "Our privacy is threatened!".

The Bytebury Security Bureau (BSB) fears that these slogans may cause an overwhelming majority of Bytebury residents to withdraw money from the banks and delete the social media accounts that BSB uses for population surveillance. Put plainly, the situation in Bytebury might become quite unstable.

To prevent this destabilization, BSB officers intend to organize a counter-manifestation promoting the belief in the inequality P≠NPP\neq \mathit{NP}. At the same time, they plan to peacefully block the parade. BSB intends to start the counter-manifestation suddenly, at one of the junctions located on the parade's route. Unfortunately, the exact route of the P=NPP=\mathit{NP} Equality Parade is kept secret until the very end, so the Bureau needs to prepare the place for the counter-manifestation in advance. BSB only knows that the parade will start at some junction, pass through a non-zero number of roads, and finally return to the starting point. Your first task is to verify this information, that is, to check whether the Bytebury road network allows such a route to exist. Also, the agents want to know whether there are any junctions that the parade has to pass through, assuming the information is confirmed. They asked you to find all such junctions. One of them will be chosen as the most convenient location for the counter-manifestation. If no such junction exists, BSB will proceed to Plan B.

Input

The first line of input contains two integers nn and mm (2≤n≤500 0002\leq n\leq 500\,000, 1≤m≤1 000 0001\leq m\leq 1\,000\,000), the number of junctions and the number of roads in Bytebury, respectively. The junctions are numbered 11 through nn. The following mm lines describe the roads. The ii-th of these lines contains two integers aia_i and bib_i (1≤ai,bi≤n1\leq a_i,b_i\leq n, ai≠bia_i\neq b_i), meaning that the ii-th road leads from junction aia_i to junction bib_i. No ordered pair (ai,bi)(a_i, b_i) appears more than once in the input.

Output

If the parade cannot be routed in accordance with the information known to BSB, the output is a single line containing the word "NIE" (Polish for "no"). Otherwise, the output has two lines. The first line contains the number kk of junctions that the parade's route will certainly pass through. The second line contains those junctions in ascending order. If k=0k=0, the second line is left blank.

Examples2

  1. Example 1

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

    Input
    3 2
    1 2
    2 3
    
    Expected output
    NIE