import java.util.Scanner;

class Main {

	public static void main(String[] args) {
	
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		if(3 <= n && n <= 10000){
		int x;
		
		for(x = 3; x <= n; x++){
			
			int y = x;
			int z = 0;
			
			if(0 == y % 3){
				System.out.print(" " + x);
				z++;
			}
			
			else 
			{
				while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				}
			}
	  }
		System.out.println("");
    }
	}		
} import java.util.Scanner; Scanner java.util class Main {

	public static void main(String[] args) {
	
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		if(3 <= n && n <= 10000){
		int x;
		
		for(x = 3; x <= n; x++){
			
			int y = x;
			int z = 0;
			
			if(0 == y % 3){
				System.out.print(" " + x);
				z++;
			}
			
			else 
			{
				while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				}
			}
	  }
		System.out.println("");
    }
	}		
} Main public static void main(String[] args) {
	
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		if(3 <= n && n <= 10000){
		int x;
		
		for(x = 3; x <= n; x++){
			
			int y = x;
			int z = 0;
			
			if(0 == y % 3){
				System.out.print(" " + x);
				z++;
			}
			
			else 
			{
				while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				}
			}
	  }
		System.out.println("");
    }
	} main {
	
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		if(3 <= n && n <= 10000){
		int x;
		
		for(x = 3; x <= n; x++){
			
			int y = x;
			int z = 0;
			
			if(0 == y % 3){
				System.out.print(" " + x);
				z++;
			}
			
			else 
			{
				while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				}
			}
	  }
		System.out.println("");
    }
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc if(3 <= n && n <= 10000){
		int x;
		
		for(x = 3; x <= n; x++){
			
			int y = x;
			int z = 0;
			
			if(0 == y % 3){
				System.out.print(" " + x);
				z++;
			}
			
			else 
			{
				while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				}
			}
	  }
		System.out.println("");
    } 3 <= n && n <= 10000 3 <= n 3 n n <= 10000 n 10000 {
		int x;
		
		for(x = 3; x <= n; x++){
			
			int y = x;
			int z = 0;
			
			if(0 == y % 3){
				System.out.print(" " + x);
				z++;
			}
			
			else 
			{
				while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				}
			}
	  }
		System.out.println("");
    } int x; x for(x = 3; x <= n; x++){
			
			int y = x;
			int z = 0;
			
			if(0 == y % 3){
				System.out.print(" " + x);
				z++;
			}
			
			else 
			{
				while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				}
			}
	  } x = 3; x = 3 x 3 x <= n x n x++ x++ x {
			
			int y = x;
			int z = 0;
			
			if(0 == y % 3){
				System.out.print(" " + x);
				z++;
			}
			
			else 
			{
				while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				}
			}
	  } {
			
			int y = x;
			int z = 0;
			
			if(0 == y % 3){
				System.out.print(" " + x);
				z++;
			}
			
			else 
			{
				while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				}
			}
	  } int y = x; y x int z = 0; z 0 if(0 == y % 3){
				System.out.print(" " + x);
				z++;
			}
			
			else 
			{
				while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				}
			} 0 == y % 3 0 y % 3 y 3 {
				System.out.print(" " + x);
				z++;
			} System.out.print(" " + x) System.out.print System.out System System.out " " + x " " x z++ z {
				while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				}
			} while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				} z == 0 z 0 {
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				} if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					} 3 == y % 10 3 y % 10 y 10 {
						System.out.print(" " + x);
						z++;
					} System.out.print(" " + x) System.out.print System.out System System.out " " + x " " x z++ z y = y / 10 y y / 10 y 10 if(y < 3){
						z++;
					} y < 3 y 3 {
						z++;
					} z++ z System.out.println("") System.out.println System.out System System.out "" String[] args args
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
	
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		if(3 <= n && n <= 10000){
		int x;
		
		for(x = 3; x <= n; x++){
			
			int y = x;
			int z = 0;
			
			if(0 == y % 3){
				System.out.print(" " + x);
				z++;
			}
			
			else 
			{
				while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				}
			}
	  }
		System.out.println("");
    }
	}		
}