






'''simple docstring'''





def __UpperCAmelCase (			A			:	int	,   A			:	list[tuple[int, int, int]]						)  -> list[tuple[int, int, int]]:
			UpperCAmelCase_     :   List[Any]       =   sorted(A	,   key=lambda A						: edge[2]						)

			UpperCAmelCase_     :   List[Any]       =   list(range(A						)						)

			def find_parent(A			:	Optional[int]						):
						if i != parent[i]:
									UpperCAmelCase_     :   List[str]       =   find_parent(parent[i]						)
						return parent[i]

			UpperCAmelCase_     :   Any       =   0
			UpperCAmelCase_     :   Tuple       =   []

			for edge in edges:
						UpperCAmelCase_     :   Tuple       =   find_parent(edge[0]						)
						UpperCAmelCase_     :   Any       =   find_parent(edge[1]						)
						if parent_a != parent_b:
									minimum_spanning_tree_cost += edge[2]
									minimum_spanning_tree.append(A						)
									UpperCAmelCase_     :   List[Any]       =   parent_b

			return minimum_spanning_tree


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

						for _ in range(num_edges):
												_UpperCamelCase		:		List[Any]								=			(int(x) for x in input().strip().split())
												edges.append((nodea, nodea, cost))

						kruskal(num_nodes, edges)










'''simple docstring'''





def __UpperCAmelCase (			)  -> Optional[Any]:
			UpperCAmelCase_     :   Union[str, Any]       =   1

			while True:
						if (
						    sorted(str(A						)						)
						    == sorted(str(2 * i						)						)
						    == sorted(str(3 * i						)						)
						    == sorted(str(4 * i						)						)
						    == sorted(str(5 * i						)						)
						    == sorted(str(6 * i						)						)
						):
									return i

						i += 1


if __name__ == "__main__":
						print(solution())


