AdvancedRating 1600
Fewest Semesters
Courses have prerequisites 'a b' (a must be passed before b). Any number of courses can be taken in one semester once their prerequisites are done. Print the fewest semesters to take all n courses, or -1 if impossible.
Input
n and m; then m lines 'a b'.
Output
One integer.
Sample 1
Input
3 2 1 3 2 3
Output
2
Sample 2
Input
3 3 1 2 2 3 3 1
Output
-1
Output appears here