Directed Cycle Detection


You are given a directed graph with nn vertices and mm edges. Each edge goes from one vertex to another, and vertices are numbered from 11 to nn.

Determine whether the graph contains at least one directed cycle. A directed cycle is a sequence of one or more edges that starts and ends at the same vertex while following edge directions.

Input

The first line contains two integers nn and mm: the number of vertices and directed edges.

The next mm lines each contain two integers aa and bb, meaning there is a directed edge from vertex aa to vertex bb.

Output

Print YES if the graph contains at least one directed cycle. Otherwise, print NO.

Constraints

  • 1≤n≤2000001 \le n \le 200000
  • 0≤m≤3000000 \le m \le 300000
  • 1≤a,b≤n1 \le a, b \le n

Example 1

Input 1
4 3
1 2
2 3
3 4
Output 1
NO
Explanation

All edges move forward along the chain, so it is impossible to return to a previous vertex.

Example 2

Input 2
4 4
1 2
2 3
3 1
3 4
Output 2
YES
Explanation

The edges 1→21 \to 2, 2→32 \to 3, and 3→13 \to 1 form a directed cycle.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.

Directed Cycle Detection - MAPS Online Judge