Question
Factory Assembly Order

A factory has N assembly tasks. Some tasks must be completed before other tasks can begin. The manager wants to know whether all tasks can be scheduled without breaking any dependency.

The twist: a circular dependency may be hidden across several tasks.

Input

The first line contains two integers KaTeX can only parse string typed expression and KaTeX can only parse string typed expression — the number of tasks and dependency rules.

Each of the next KaTeX can only parse string typed expression lines contains two integers KaTeX can only parse string typed expression and KaTeX can only parse string typed expression, meaning task KaTeX can only parse string typed expression must be completed before task KaTeX can only parse string typed expression.

Output

Print KaTeX can only parse string typed expression if all tasks can be completed, otherwise print KaTeX can only parse string typed expression.

Example
Example 1:
Input
5 4

1 2
1 3
3 4
2 5
Output
YES
Explanation
One valid order is KaTeX can only parse string typed expression.

Example 2:
Input
3 3

1 2
2 3
3 1
Output
NO
Explanation
The tasks depend on each other in a cycle.

Online