"""simple docstring"""







def 					a__ (						UpperCAmelCase__    :     int						,     UpperCAmelCase__    :     list[tuple[int, int, int]]     ):
						UpperCAmelCase__   		=						sorted(_UpperCAmelCase						,     key=lambda UpperCAmelCase__     : edge[2]     )

						UpperCAmelCase__   		=						list(range(_UpperCAmelCase     )     )

						def find_parent(UpperCAmelCase__    :     Dict     ):
												if i != parent[i]:
																		UpperCAmelCase__   		=						find_parent(parent[i]     )
												return parent[i]

						UpperCAmelCase__   		=						0
						UpperCAmelCase__   		=						[]

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

						return minimum_spanning_tree


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

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

						kruskal(num_nodes, edges)


"""simple docstring"""







from __future__ import annotations

from collections import Counter


def 					a__ (						UpperCAmelCase__    :     int     )->		list[int]:
						UpperCAmelCase__   		=						[True] * n
						UpperCAmelCase__   		=						False
						UpperCAmelCase__   		=						False
						UpperCAmelCase__   		=						True

						for i in range(3						,     int(n**0.5 + 1     )						,     2     ):
												UpperCAmelCase__   		=						i * 2
												while index < n:
																		UpperCAmelCase__   		=						False
																		UpperCAmelCase__   		=						index + i

						UpperCAmelCase__   		=						[2]

						for i in range(3						,     UpperCAmelCase__						,     2     ):
												if is_prime[i]:
																		primes.append(UpperCAmelCase__     )

						return primes


def 					a__ (						UpperCAmelCase__    :     int     )->		list[list[int]]:
						UpperCAmelCase__   		=						str(UpperCAmelCase__     )
						UpperCAmelCase__   		=						[]
						UpperCAmelCase__   		=						["""0""", """1""", """2""", """3""", """4""", """5""", """6""", """7""", """8""", """9"""]

						for duplicate in Counter(UpperCAmelCase__     ) - Counter(set(UpperCAmelCase__     )     ):
												UpperCAmelCase__   		=						[int(number_str.replace(UpperCAmelCase__						,     UpperCAmelCase__     )     ) for digit in digits]
												replacements.append(UpperCAmelCase__     )

						return replacements


def 					a__ (						UpperCAmelCase__    :     int = 8     )->		int:
						UpperCAmelCase__   		=						set()

						# Filter primes with less than 3 replaceable digits
						UpperCAmelCase__   		=						{
						    x for x in set(prime_sieve(1_0_0_0_0_0_0     )     ) if len(str(UpperCAmelCase__     )     ) - len(set(str(UpperCAmelCase__     )     )     ) >= 3
						}

						for prime in primes:
												if prime in numbers_checked:
																		continue

												UpperCAmelCase__   		=						digit_replacements(UpperCAmelCase__     )

												for family in replacements:
																		numbers_checked.update(UpperCAmelCase__     )
																		UpperCAmelCase__   		=						primes.intersection(UpperCAmelCase__     )

																		if len(UpperCAmelCase__     ) != family_length:
																								continue

																		return min(UpperCAmelCase__     )

						return -1


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

