Course Schedule

MediumGraphs
Next
GraphTopological SortCycle Detection

You must take n courses numbered 0 to n - 1. Some courses have prerequisites: a pair (a, b) means you must take course b before course a. Decide whether it is possible to finish all the courses.

Input

Line 1: n and m, the number of courses and prerequisite pairs. Next m lines: a b (take b before a).

Output

Print true if all courses can be completed, otherwise false.

Constraints

1 <= n <= 2000 0 <= m <= 5000

Example 1
Input
2 1
1 0
Output
true

Take course 0 first, then course 1.

Example 2
Input
2 2
1 0
0 1
Output
false

Each course requires the other: a cycle.

Hints

Course Schedule - Medium Graphs Problem | Skill Shiksha