import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		
		
		for(long i = 1;i <= n;i++){
			long x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
				continue;
			}
			
			if(x % 10 == 3){
				System.out.print(" "+i);
				continue;
			}
			
			for(x /= 10;x != 0;x /= 10){
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			}
		}
		
		System.out.print("\n");
		
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		
		
		for(long i = 1;i <= n;i++){
			long x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
				continue;
			}
			
			if(x % 10 == 3){
				System.out.print(" "+i);
				continue;
			}
			
			for(x /= 10;x != 0;x /= 10){
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			}
		}
		
		System.out.print("\n");
		
		sc.close();
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		
		
		for(long i = 1;i <= n;i++){
			long x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
				continue;
			}
			
			if(x % 10 == 3){
				System.out.print(" "+i);
				continue;
			}
			
			for(x /= 10;x != 0;x /= 10){
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			}
		}
		
		System.out.print("\n");
		
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		
		
		for(long i = 1;i <= n;i++){
			long x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
				continue;
			}
			
			if(x % 10 == 3){
				System.out.print(" "+i);
				continue;
			}
			
			for(x /= 10;x != 0;x /= 10){
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			}
		}
		
		System.out.print("\n");
		
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long n = sc.nextInt(); n sc.nextInt() sc.nextInt sc for(long i = 1;i <= n;i++){
			long x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
				continue;
			}
			
			if(x % 10 == 3){
				System.out.print(" "+i);
				continue;
			}
			
			for(x /= 10;x != 0;x /= 10){
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			}
		} long i = 1; long i = 1; i 1 i <= n i n i++ i++ i {
			long x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
				continue;
			}
			
			if(x % 10 == 3){
				System.out.print(" "+i);
				continue;
			}
			
			for(x /= 10;x != 0;x /= 10){
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			}
		} {
			long x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
				continue;
			}
			
			if(x % 10 == 3){
				System.out.print(" "+i);
				continue;
			}
			
			for(x /= 10;x != 0;x /= 10){
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			}
		} long x = i; x i if(x % 3 == 0){
				System.out.print(" "+i);
				continue;
			} x % 3 == 0 x % 3 x 3 0 {
				System.out.print(" "+i);
				continue;
			} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i continue; if(x % 10 == 3){
				System.out.print(" "+i);
				continue;
			} x % 10 == 3 x % 10 x 10 3 {
				System.out.print(" "+i);
				continue;
			} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i continue; for(x /= 10;x != 0;x /= 10){
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			} x /= 10; x /= 10 x 10 x != 0 x 0 x /= 10 x /= 10 x 10 {
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			} {
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			} if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				} x % 10 == 3 x % 10 x 10 3 {
					System.out.print(" "+i);
					break;
				} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i break; System.out.print("\n") System.out.print System.out System System.out "\n" sc.close() sc.close sc String[] args args public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		
		
		for(long i = 1;i <= n;i++){
			long x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
				continue;
			}
			
			if(x % 10 == 3){
				System.out.print(" "+i);
				continue;
			}
			
			for(x /= 10;x != 0;x /= 10){
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			}
		}
		
		System.out.print("\n");
		
		sc.close();
	}
} public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		
		
		for(long i = 1;i <= n;i++){
			long x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
				continue;
			}
			
			if(x % 10 == 3){
				System.out.print(" "+i);
				continue;
			}
			
			for(x /= 10;x != 0;x /= 10){
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			}
		}
		
		System.out.print("\n");
		
		sc.close();
	}
} Main
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		
		
		for(long i = 1;i <= n;i++){
			long x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
				continue;
			}
			
			if(x % 10 == 3){
				System.out.print(" "+i);
				continue;
			}
			
			for(x /= 10;x != 0;x /= 10){
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			}
		}
		
		System.out.print("\n");
		
		sc.close();
	}
}