// Arup Guha
// 8/27/2026
// Prints out all prefix primes.

import java.util.*;

public class prefixprime {

	public static ArrayList<Integer> res;
	
	public static void main(String[] args) {
		
		// Set up list and call recursive function with each starting digit.
		res = new ArrayList<Integer>();	
		for (int i=1; i<10; i++)
			go(i);
		
		// Sort answers and print them out.
		Collections.sort(res);
		for (Integer x: res)
			System.out.println(x);
	}
	
	// Prints all primes that start with prefix.
	public static void go(int prefix) {
	
		// Base case - does backtracking.
		if (!prime(prefix)) return;
		
		// Ran two versions, one just printed out, other added to a list.
		//System.out.println(prefix);
		res.add(prefix);
		
		// This is a valid prefix prime, so try tacking on each future digit.
		for (int i=0; i<10; i++)
			go(prefix*10 + i);
	}
	
	// Returns true iff n is prime.
	public static boolean prime(int n) {
		
		// Primes start at 2.
		if (n<2) return false;
		
		// We just need to do trial division to the square root.
		// We avoid using doubles with i*i <= n...
		for (int i=2; i*i<=n; i++)
			if (n%i == 0)
				return false;
				
		// We know it's prime if we get here.
		return true;
	}
}