import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		int i = 1;

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

	}

} import java.util.Scanner; Scanner java.util class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		int i = 1;

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

	}

} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		int i = 1;

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

	} main {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		int i = 1;

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

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan scan.close() scan.close scan int i = 1; i 1 do{
			int x = i;
			if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				do{
					if(x % 10 == 3){
						System.out.print(" " + i);
						break;
					}else{
						x /= 10;
					}
				}while(x != 0);
			}
		}while( ++i <= n); ++i <= n ++i i n {
			int x = i;
			if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				do{
					if(x % 10 == 3){
						System.out.print(" " + i);
						break;
					}else{
						x /= 10;
					}
				}while(x != 0);
			}
		} int x = i; x i if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				do{
					if(x % 10 == 3){
						System.out.print(" " + i);
						break;
					}else{
						x /= 10;
					}
				}while(x != 0);
			} x % 3 == 0 x % 3 x 3 0 {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
				do{
					if(x % 10 == 3){
						System.out.print(" " + i);
						break;
					}else{
						x /= 10;
					}
				}while(x != 0);
			} do{
					if(x % 10 == 3){
						System.out.print(" " + i);
						break;
					}else{
						x /= 10;
					}
				}while(x != 0); x != 0 x 0 {
					if(x % 10 == 3){
						System.out.print(" " + i);
						break;
					}else{
						x /= 10;
					}
				} if(x % 10 == 3){
						System.out.print(" " + i);
						break;
					}else{
						x /= 10;
					} 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; {
						x /= 10;
					} x /= 10 x 10 System.out.print("\n") System.out.print System.out System System.out "\n" String[] args args
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		int i = 1;

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

	}

}