'''simple docstring'''




from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
_lowercase		:					Optional[int]													=		[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]




def 				lowerCamelCase      ( UpperCAmelCase__			:   int					)     -> list[int]:
							return [int(UpperCAmelCase__					) for c in F'''{ruleset:08}'''[:8]]




def 				lowerCamelCase      ( UpperCAmelCase__			:   list[list[int]] , UpperCAmelCase__			:   list[int] , UpperCAmelCase__			:   int					)     -> list[int]:
							lowercase_   :     List[str]									=			len(cells[0]					)  # 31
							lowercase_   :     List[Any]									=			[]
							for i in range(UpperCAmelCase__					):
														# Get the neighbors of each cell
														# Handle neighbours outside bounds by using 0 as their value
														lowercase_   :     Optional[int]									=			0 if i == 0 else cells[time][i - 1]
														lowercase_   :     Tuple									=			0 if i == population - 1 else cells[time][i + 1]
														# Define a new cell and add it to the new generation
														lowercase_   :     List[Any]									=			7 - int(F'''{left_neighbor}{cells[time][i]}{right_neighbor}''' , 2					)
														next_generation.append(rule[situation]					)
							return next_generation




def 				lowerCamelCase      ( UpperCAmelCase__			:   list[list[int]]					)     -> Image.Image:
							lowercase_   :     Dict									=			Image.new("""RGB""" , (len(cells[0]					), len(UpperCAmelCase__					))					)
							lowercase_   :     Optional[Any]									=			img.load()
							# Generates image
							for w in range(img.width					):
														for h in range(img.height					):
																					lowercase_   :     List[Any]									=			255 - int(255 * cells[h][w]					)
																					lowercase_   :     Any									=			(color, color, color)
							return img


if __name__ == "__main__":
						_lowercase		:					int													=		bin(int(input("Rule:\n").strip()))[2:]
						_lowercase		:					List[str]													=		format_ruleset(int(rule_num))
						for time in range(16):
												CELLS.append(new_generation(CELLS, rule, time))
						_lowercase		:					str													=		generate_image(CELLS)
						# Uncomment to save the image
						# img.save(f"rule_{rule_num}.png")
						img.show()






'''simple docstring'''




from __future__ import annotations




def 				lowerCamelCase      ( UpperCAmelCase__			:   str					)     -> Any:
							global graph, reversed_graph, scc, component, visit, stack
							if visit[u]:
														return
							lowercase_   :     int									=			True
							for v in graph[u]:
														dfs(UpperCAmelCase__					)
							stack.append(UpperCAmelCase__					)




def 				lowerCamelCase      ( UpperCAmelCase__			:   int					)     -> str:
							global graph, reversed_graph, scc, component, visit, stack
							if visit[u]:
														return
							lowercase_   :     Tuple									=			True
							component.append(UpperCAmelCase__					)
							for v in reversed_graph[u]:
														dfsa(UpperCAmelCase__					)




def 				lowerCamelCase      ( )     -> int:
							global graph, reversed_graph, scc, component, visit, stack
							for i in range(UpperCAmelCase__					):
														dfs(UpperCAmelCase__					)
							lowercase_   :     Optional[int]									=			[False] * n
							for i in stack[::-1]:
														if visit[i]:
																					continue
														lowercase_   :     Union[str, Any]									=			[]
														dfsa(UpperCAmelCase__					)
														scc.append(UpperCAmelCase__					)
							return scc


if __name__ == "__main__":
						# n - no of nodes, m - no of edges
						_lowercase							,			_lowercase		:					Optional[Any]													=		list(map(int, input().strip().split()))

						_lowercase		:					list[list[int]]													=		[[] for _ in range(n)]  # graph
						_lowercase		:					list[list[int]]													=		[[] for i in range(n)]  # reversed graph
						# input graph data (edges)
						for _ in range(m):
												_lowercase							,			_lowercase		:					Tuple													=		list(map(int, input().strip().split()))
												graph[u].append(v)
												reversed_graph[v].append(u)

						_lowercase		:					list[int]													=		[]
						_lowercase		:					list[bool]													=		[False] * n
						_lowercase		:					list[int]													=		[]
						_lowercase		:					list[int]													=		[]
						print(kosaraju())





