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

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

	used[u] = 1
	#print(u, used)
	for v in graph.get(u, []):
		if used[v] == 0:
			dfs(v)
		elif used[u] == 1:
			found = True
	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 not used[i]:
		dfs(i)
	if found:
		break

if not found:
	print('NO')
	exit()
print('YES')