e-olymp
Competitions

ADA Classes - November 20

Find a cycle

The directed and unweighted graph is given. Determine, does it contain a cycle. If yes, then print any of them.

Input

The first line contains two positive integers n and m (1n105, 1m105) - the number of vertices and edges in graph respectively. In the next m lines the edges are given. Each edge is described with a pair of numbers - the numbers of initial and final vertex respectively.

Output

If the graph does not contain the cycle, print "NO", otherwise print "YES" and then the list of vertices in the order of cycle traversal.

Time limit 1 second
Memory limit 128 MiB
Input example #1
2 2
1 2
2 1
Output example #1
YES
1 2
Input example #2
2 2
1 2
1 2
Output example #2
NO
Source ЛКШ-2011 Севастополь 08.08.2011 д.1 1-я лига