import sys
sys.setrecursionlimit(10 ** 5)

def readList():
    return [int(i) for i in input().split()]

def dfs(u):
	global graph
	global used
	global n

	used[u] = 1
	for v in graph.get(u, []):
		if used[v] == 1:
			return 1
		if used[v] == 0:
			if dfs(v) == 1:
				return 1
	used[u] = 2

n, m = readList()
graph = {}
for i in range(m):
	a, b = readList()
	if graph.get(a, 0) == 0:
		graph[a] = [b]
	else:
		graph[a].append(b)
used = [0] * (n + 1)
found = False
for i in range(1, n + 1):
	if dfs(i): found = True
if not found:
	print('NO')