n, m = map(int, input().split()) next = [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 next[a].append(b) topo = [] done = [False for _ in range(n)] callbacks = [[] for _ in range(n)] topo_id = [None for _ in range(n)] for node in range(n): if done[node]: continue todo = [node] while todo: node = todo.pop() if done[node]: continue topo_id[node] = len(topo) topo.append(node) done[node] = True for next_node in next[node]: if done[next_node]: #print("a", node, next_node) callbacks[topo_id[node]].append(topo_id[next_node]) continue todo.append(next_node) for c in callbacks: c.sort() # print(callbacks) def SUM(a, b): if a is None or b is None: return None for i in range(3): a[i].extend(b[i]) return a def SHUFFLE(a, b, c): if a is None or b is None or c is None: return None return [[*a[0], *b[0], *c[0]], [*b[1], *c[1], *a[1]], [*c[2], *a[2], *b[2]]] def rec(start, end): if start > end: return [[], [], []] if not callbacks[end]: return SUM(rec(start, end-1), [[end], [end], [end]]) if callbacks[end][0] < start: return None if len(callbacks[end]) == 1: return SHUFFLE(rec(start, callbacks[end][0]), rec(callbacks[end][0]+1, end-1), [[end], [end], [end]]) else: q = callbacks.pop(0) return SHUFFLE(rec(start, q), rec(q+1, q+1), rec(q+1, end)) res = rec(0, n-1) if res is None: print("NO") else: print("YES") print(3) for line in res: print(*list(map(lambda x: topo[x]+1, line)))