import java.util.*;
import java.io.*;

class Main {
	static PrintStream out = System.out;
	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int n = in.nextInt();

		int i = 1;
		do {
			int x = i;
			if ( x % 3 == 0 ){
				out.print(" " + i);
			} else {
				do{
					if(x % 10 == 3){
						out.print(" " + i);
						break;
					}
					x /= 10;
				}while(x != 0);
			}
		}while( ++i <= n );

		out.println();
	}
} import java.util.*; util.* java import java.io.*; io.* java class Main {
	static PrintStream out = System.out;
	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int n = in.nextInt();

		int i = 1;
		do {
			int x = i;
			if ( x % 3 == 0 ){
				out.print(" " + i);
			} else {
				do{
					if(x % 10 == 3){
						out.print(" " + i);
						break;
					}
					x /= 10;
				}while(x != 0);
			}
		}while( ++i <= n );

		out.println();
	}
} Main static PrintStream out = System.out; out System.out System System.out static Scanner in = new Scanner(System.in); in new Scanner(System.in) public static void main(String[] args) {
		int n = in.nextInt();

		int i = 1;
		do {
			int x = i;
			if ( x % 3 == 0 ){
				out.print(" " + i);
			} else {
				do{
					if(x % 10 == 3){
						out.print(" " + i);
						break;
					}
					x /= 10;
				}while(x != 0);
			}
		}while( ++i <= n );

		out.println();
	} main {
		int n = in.nextInt();

		int i = 1;
		do {
			int x = i;
			if ( x % 3 == 0 ){
				out.print(" " + i);
			} else {
				do{
					if(x % 10 == 3){
						out.print(" " + i);
						break;
					}
					x /= 10;
				}while(x != 0);
			}
		}while( ++i <= n );

		out.println();
	} int n = in.nextInt(); n in.nextInt() in.nextInt in int i = 1; i 1 do {
			int x = i;
			if ( x % 3 == 0 ){
				out.print(" " + i);
			} else {
				do{
					if(x % 10 == 3){
						out.print(" " + i);
						break;
					}
					x /= 10;
				}while(x != 0);
			}
		}while( ++i <= n ); ++i <= n ++i i n {
			int x = i;
			if ( x % 3 == 0 ){
				out.print(" " + i);
			} else {
				do{
					if(x % 10 == 3){
						out.print(" " + i);
						break;
					}
					x /= 10;
				}while(x != 0);
			}
		} int x = i; x i if ( x % 3 == 0 ){
				out.print(" " + i);
			} else {
				do{
					if(x % 10 == 3){
						out.print(" " + i);
						break;
					}
					x /= 10;
				}while(x != 0);
			} x % 3 == 0 x % 3 x 3 0 {
				out.print(" " + i);
			} out.print(" " + i) out.print out " " + i " " i {
				do{
					if(x % 10 == 3){
						out.print(" " + i);
						break;
					}
					x /= 10;
				}while(x != 0);
			} do{
					if(x % 10 == 3){
						out.print(" " + i);
						break;
					}
					x /= 10;
				}while(x != 0); x != 0 x 0 {
					if(x % 10 == 3){
						out.print(" " + i);
						break;
					}
					x /= 10;
				} if(x % 10 == 3){
						out.print(" " + i);
						break;
					} x % 10 == 3 x % 10 x 10 3 {
						out.print(" " + i);
						break;
					} out.print(" " + i) out.print out " " + i " " i break; x /= 10 x 10 out.println() out.println out String[] args args
import java.util.*;
import java.io.*;

class Main {
	static PrintStream out = System.out;
	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int n = in.nextInt();

		int i = 1;
		do {
			int x = i;
			if ( x % 3 == 0 ){
				out.print(" " + i);
			} else {
				do{
					if(x % 10 == 3){
						out.print(" " + i);
						break;
					}
					x /= 10;
				}while(x != 0);
			}
		}while( ++i <= n );

		out.println();
	}
}