Under construction

Still being built. Things may change

Triball Ranking

Interview

Time limit2sMemory limit512 MB

Summary
Order all k players to satisfy every match result and return the lexicographically smallest lineup, or 0 when no lineup fits.
Level

Medium4 of 10

Topics
Topological sort, Graph, Heap
Solved
No attempts yet

Problem

Triball is a sport proposed for the Youth Olympic Games in Singapore. It is played by kk players numbered 11 through kk. Every match puts three distinct players on the court, and the result names either the one player who won or the one player who lost.

Say match ii is played by pi1p_{i1}, pi2p_{i2}, pi3p_{i3}. A result written as pi1>pi2,pi3p_{i1} > p_{i2}, p_{i3} means pi1p_{i1} won, so pi1p_{i1} is better than pi2p_{i2} and better than pi3p_{i3}. A result written as pi2,pi3>pi1p_{i2}, p_{i3} > p_{i1} means pi1p_{i1} lost, so pi2p_{i2} is better than pi1p_{i1} and pi3p_{i3} is better than pi1p_{i1}.

You are given the results of nn matches. Line up all kk players so that a better player always comes before a worse one. When more than one lineup satisfies every result, answer with the lexicographically smallest one, comparing lineups as sequences of player numbers. When no lineup satisfies every result, print 00.

Input

The first line contains the number of players kk and the number of matches nn, separated by a space. (1≤k≤10001 \le k \le 1000, 1≤n≤100001 \le n \le 10000)

Each of the next nn lines holds one match result. A line is written without spaces as p1>p2,p3 or as p2,p3>p1, and the three players in a match are distinct.

Output

If a lineup satisfying every result exists, print the kk player numbers of the lexicographically smallest such lineup on one line, separated by single spaces. Otherwise print 00.

Examples2

  1. Example 1

    Input
    6 5
    4>1,3
    3>1,2
    2,5>6
    5>2,3
    1>2,6
    
    Expected output
    4 5 3 1 2 6
    
  2. Example 2

    Input
    4 2
    1>2,4
    2,4>1
    
    Expected output
    0