import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int intInput = scan.nextInt();
		for(int i = 1; i <= intInput; 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(intInput == i){
				System.out.println("");
			}
		}
		scan.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int intInput = scan.nextInt();
		for(int i = 1; i <= intInput; 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(intInput == i){
				System.out.println("");
			}
		}
		scan.close();
	}
} Main public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int intInput = scan.nextInt();
		for(int i = 1; i <= intInput; 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(intInput == i){
				System.out.println("");
			}
		}
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int intInput = scan.nextInt();
		for(int i = 1; i <= intInput; 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(intInput == i){
				System.out.println("");
			}
		}
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int intInput = scan.nextInt(); intInput scan.nextInt() scan.nextInt scan for(int i = 1; i <= intInput; 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(intInput == i){
				System.out.println("");
			}
		} int i = 1; int i = 1; i 1 i <= intInput i intInput 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(intInput == i){
				System.out.println("");
			}
		} {
			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(intInput == i){
				System.out.println("");
			}
		} 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 if(intInput == i){
				System.out.println("");
			} intInput == i intInput i {
				System.out.println("");
			} System.out.println("") System.out.println System.out System System.out "" scan.close() scan.close scan String[] args args public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int intInput = scan.nextInt();
		for(int i = 1; i <= intInput; 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(intInput == i){
				System.out.println("");
			}
		}
		scan.close();
	}
} public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int intInput = scan.nextInt();
		for(int i = 1; i <= intInput; 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(intInput == i){
				System.out.println("");
			}
		}
		scan.close();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int intInput = scan.nextInt();
		for(int i = 1; i <= intInput; 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(intInput == i){
				System.out.println("");
			}
		}
		scan.close();
	}
}