public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int x = scan.nextInt();
		for(int i = 1;i <= x; i++){
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else if(i % 10 == 3){
				System.out.print(" " + i);
			}else if(String.valueOf(i).contains("3")){
				System.out.print(" " + i);
			}
		}
		System.out.println();
	}

} public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int x = scan.nextInt();
		for(int i = 1;i <= x; i++){
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else if(i % 10 == 3){
				System.out.print(" " + i);
			}else if(String.valueOf(i).contains("3")){
				System.out.print(" " + i);
			}
		}
		System.out.println();
	}

} Main public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int x = scan.nextInt();
		for(int i = 1;i <= x; i++){
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else if(i % 10 == 3){
				System.out.print(" " + i);
			}else if(String.valueOf(i).contains("3")){
				System.out.print(" " + i);
			}
		}
		System.out.println();
	} main {
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int x = scan.nextInt();
		for(int i = 1;i <= x; i++){
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else if(i % 10 == 3){
				System.out.print(" " + i);
			}else if(String.valueOf(i).contains("3")){
				System.out.print(" " + i);
			}
		}
		System.out.println();
	} java.util.Scanner scan = new java.util.Scanner(System.in); scan new java.util.Scanner(System.in) int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan for(int i = 1;i <= x; i++){
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else if(i % 10 == 3){
				System.out.print(" " + i);
			}else if(String.valueOf(i).contains("3")){
				System.out.print(" " + i);
			}
		} int i = 1; int i = 1; i 1 i <= x i x i++ i++ i {
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else if(i % 10 == 3){
				System.out.print(" " + i);
			}else if(String.valueOf(i).contains("3")){
				System.out.print(" " + i);
			}
		} {
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else if(i % 10 == 3){
				System.out.print(" " + i);
			}else if(String.valueOf(i).contains("3")){
				System.out.print(" " + i);
			}
		} if(i % 3 == 0){
				System.out.print(" " + i);
			}else if(i % 10 == 3){
				System.out.print(" " + i);
			}else if(String.valueOf(i).contains("3")){
				System.out.print(" " + i);
			} i % 3 == 0 i % 3 i 3 0 {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if(i % 10 == 3){
				System.out.print(" " + i);
			}else if(String.valueOf(i).contains("3")){
				System.out.print(" " + i);
			} i % 10 == 3 i % 10 i 10 3 {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if(String.valueOf(i).contains("3")){
				System.out.print(" " + i);
			} String.valueOf(i).contains("3") String.valueOf(i).contains String.valueOf(i) String.valueOf String i "3" {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int x = scan.nextInt();
		for(int i = 1;i <= x; i++){
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else if(i % 10 == 3){
				System.out.print(" " + i);
			}else if(String.valueOf(i).contains("3")){
				System.out.print(" " + i);
			}
		}
		System.out.println();
	}

} public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int x = scan.nextInt();
		for(int i = 1;i <= x; i++){
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else if(i % 10 == 3){
				System.out.print(" " + i);
			}else if(String.valueOf(i).contains("3")){
				System.out.print(" " + i);
			}
		}
		System.out.println();
	}

} Main
public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int x = scan.nextInt();
		for(int i = 1;i <= x; i++){
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else if(i % 10 == 3){
				System.out.print(" " + i);
			}else if(String.valueOf(i).contains("3")){
				System.out.print(" " + i);
			}
		}
		System.out.println();
	}

}