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

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

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

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 used[i] == 0:
		if dfs(0, i) == 1:
			found = True
			break
if not found:
	print('NO')