Under construction

Still being built. Things may change

Counter-demonstration

Time limit2sMemory limit512 MB

Summary
Given a directed graph, decide whether it contains a cycle and list every intersection that lies on all cycles.
Level

Medium7 of 10

Topics
Graph, DFS, Topological sort
Solved
No attempts yet

Statement

Every year, Bitowice hosts the P = NP Equality Parade. It is an event where people who believe that for every language LL recognized in polynomial time by some nondeterministic Turing machine, there is also a deterministic Turing machine recognizing LL in polynomial time, express their views to the public. ∗ Previous parades were peaceful. Participants at most shouted "3-SAT is easy!" or held banners with pseudocode of the newest polynomial "algorithms" for finding Hamiltonian cycles, and passersby hardly noticed. This year the organizers want to draw the attention of Bitowice residents and plan to chant more shocking slogans (which are partly true if P = NP), for example "Our money is not safe!" and "Our privacy is under threat!". Officers of the Bitowice Security Agency (ABB) fear that the messages of the parade may lead residents to withdraw their money from banks en masse and delete their accounts on the social networks that ABB uses to monitor the population. In short, they suspect the situation in Bitowice will become unstable. To prevent this destabilization, ABB officers plan a counter-demonstration promoting belief in P≠NPP \neq NP. At the same time, they plan to peacefully block the parade from passing. ABB intends to start the counter-demonstration suddenly at one of the intersections on the parade route. The exact route of the P = NP parade is kept secret until the very end, so the agency must prepare the counter-demonstration location in advance. ABB has only received a tip that the parade will start at a certain intersection, run along a nonzero number of roads, and finally return to its starting point. Your first task is to verify this information in advance, that is, check whether Bitowice's road network allows such a route to exist. The agents also want to know whether there are intersections that the parade route must pass through if the tip is confirmed. They asked you to find all such intersections. From them, they will choose the most convenient location for the counter-demonstration. If no such intersections exist, ABB will move to plan B. Bitowice has nn intersections connected by one-way roads. Since the parade also includes motor vehicles, we assume that the parade can move only in the direction of the roads. ∗ For more information on the P versus NP problem, see http://en.wikipedia.org/wiki/P_versus_NP_problem.

Input

The first line contains two integers nn and mm (2≤n≤500 0002 \le n \le 500\,000, 1≤m≤1 000 0001 \le m \le 1\,000\,000), the number of intersections and the number of roads in Bitowice. Intersections are numbered from 11 to nn. Each of the next mm lines describes a road. The ii-th line contains two integers aia_i and bib_i (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i), meaning that the ii-th road leads from intersection aia_i to intersection bib_i. No ordered pair (ai,bi)(a_i, b_i) appears more than once.

Output

If the parade cannot be organized along a route consistent with the information ABB has, print a single line containing NIE. Otherwise, print two lines. The first line contains the number kk of intersections that the parade route will certainly pass through. The second line contains the kk numbers of these intersections in increasing order. If k=0k = 0, leave the second line empty.

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