

from __future__ import annotations

from collections import Counter
def 						UpperCamelCase_(			snake_case__:  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  ,    snake_case__  ,    2   ):
  if is_prime[i]:
   primes.append(snake_case__   )

 return primes
def 						UpperCamelCase_(			snake_case__:  int   )       -> list[list[int]]:
 UpperCAmelCase__							=				str(snake_case__   )
 UpperCAmelCase__							=				[]
 UpperCAmelCase__							=				['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

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

 return replacements
def 						UpperCamelCase_(			snake_case__:  int = 8   )       -> int:
 UpperCAmelCase__							=				set()

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

 for prime in primes:
  if prime in numbers_checked:
   continue

  UpperCAmelCase__							=				digit_replacements(snake_case__   )

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

   if len(snake_case__   ) != family_length:
    continue

   return min(snake_case__   )

 return -1


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







'''simple docstring'''






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__UpperCAmelCase    				=							{
    '''configuration_switch_transformers''': [
        '''SWITCH_TRANSFORMERS_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''SwitchTransformersConfig''',
        '''SwitchTransformersOnnxConfig''',
    ]
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__UpperCAmelCase    				=							[
		    '''SWITCH_TRANSFORMERS_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''SwitchTransformersEncoderModel''',
		    '''SwitchTransformersForConditionalGeneration''',
		    '''SwitchTransformersModel''',
		    '''SwitchTransformersPreTrainedModel''',
		    '''SwitchTransformersTop1Router''',
		    '''SwitchTransformersSparseMLP''',
		]


if TYPE_CHECKING:
		from .configuration_switch_transformers import (
		    SWITCH_TRANSFORMERS_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    SwitchTransformersConfig,
		    SwitchTransformersOnnxConfig,
		)

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_switch_transformers import (
				    SWITCH_TRANSFORMERS_PRETRAINED_MODEL_ARCHIVE_LIST,
				    SwitchTransformersEncoderModel,
				    SwitchTransformersForConditionalGeneration,
				    SwitchTransformersModel,
				    SwitchTransformersPreTrainedModel,
				    SwitchTransformersSparseMLP,
				    SwitchTransformersTopaRouter,
				)


else:
		import sys

		__UpperCAmelCase    				=							_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)