


from __future__ import annotations

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Optional[Any]	)     ->	Tuple:



	"""simple docstring"""






	global graph, reversed_graph, scc, component, visit, stack
	if visit[u]:
		return
	a_     			=   True
	for v in graph[u]:
		dfs(UpperCamelCase	)
	stack.append(UpperCamelCase	)

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Union[str, Any]	)     ->	Optional[int]:



	"""simple docstring"""






	global graph, reversed_graph, scc, component, visit, stack
	if visit[u]:
		return
	a_     			=   True
	component.append(UpperCamelCase	)
	for v in reversed_graph[u]:
		dfsa(UpperCamelCase	)

def 			__SCREAMING_SNAKE_CASE		(		)     ->	List[str]:



	"""simple docstring"""






	global graph, reversed_graph, scc, component, visit, stack
	for i in range(UpperCamelCase	):
		dfs(UpperCamelCase	)
	a_     			=   [False] * n
	for i in stack[::-1]:
		if visit[i]:
			continue
		a_     			=   []
		dfsa(UpperCamelCase	)
		scc.append(UpperCamelCase	)
	return scc


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

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

			_A							     =       []
			_A							     =       [False] * n
			_A							     =       []
			_A							     =       []
			print(kosaraju())



def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      int     ,					UpperCamelCase		:      list[tuple[int, int, int]]	)     ->	list[tuple[int, int, int]]:



	"""simple docstring"""






	a_     			=   sorted(UpperCamelCase     ,					key=lambda UpperCamelCase	: edge[2]	)

	a_     			=   list(range(UpperCamelCase	)	)

	def find_parent(UpperCamelCase		:      Any	):
		if i != parent[i]:
			a_     			=   find_parent(parent[i]	)
		return parent[i]

	a_     			=   0
	a_     			=   []

	for edge in edges:
		a_     			=   find_parent(edge[0]	)
		a_     			=   find_parent(edge[1]	)
		if parent_a != parent_b:
			minimum_spanning_tree_cost += edge[2]
			minimum_spanning_tree.append(UpperCamelCase	)
			a_     			=   parent_b

	return minimum_spanning_tree


if __name__ == "__main__":  # pragma: no cover
			_A     ,				_A							     =       list(map(int, input().strip().split()))
			_A							     =       []

			for _ in range(num_edges):
						_A     ,				_A     ,				_A							     =       (int(x) for x in input().strip().split())
						edges.append((nodea, nodea, cost))

			kruskal(num_nodes, edges)