This page is still under construction.

Parts of this page are still being built. What you see may change.

Credibility of Witnesses

Time limit1sMemory limit128 MB

Summary
Given agree/disagree statements between witnesses, find all witnesses whose implied relations force them to both agree and disagree with some other witness.
Level

Hard8 of 10

Topics
Graph, Union-find, Topological sort
Solved
No attempts yet

Problem

There are nn witnesses, numbered from 11 to nn, testifying in court. Each testimony has one of two forms:

  • witness ii agrees with witness jj, or
  • witness ii does not agree with witness jj.

Agreement carries over other witnesses' opinions. Specifically, if witness ii agrees with witness jj, then:

  • witness ii agrees with every witness that witness jj agrees with, and
  • witness ii does not agree with every witness that witness jj does not agree with.

Every witness always agrees with themselves.

Witness AA is not credible if the testimonies together imply that there is some witness BB for whom witness AA both agrees with BB and does not agree with BB.

Given all testimonies, find every witness who is not credible.

Input

The first line contains an integer nn (1≤n≤30001 \le n \le 3000), the number of witnesses. The second line contains an integer mm (0≤m≤80000 \le m \le 8000), the number of testimonies.

Each of the next mm lines contains two integers ii and jj (1≤i≤n1 \le i \le n, 1≤∣j∣≤n1 \le |j| \le n). If jj is positive, the line means "witness ii agrees with witness jj". If jj is negative, it means "witness ii does not agree with witness −j-j".

Output

Print one of the following:

  • the single word NIKT (which means "nobody"), if no witness is not credible, or
  • the numbers of all witnesses who are not credible, in increasing order, one per line.

Examples1

  1. Example 1

    Input
    6
    12
    1 3
    1 6
    2 -1
    3 4
    4 1
    4 -2
    4 5
    5 -1
    5 -3
    5 2
    6 5
    6 4
    
    Expected output
    1
    3
    4
    6