import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
class Main{
	public static void main(String[] args){
	int n =0;
	int x =0;
	Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		for(int i=1; i != n+1; i++){
			x = i;
			if(i%3 == 0){
				System.out.print(" "+i);
			}
			else{
				while(x != 0){
					if(x%10 == 3){
						System.out.print(" "+i);
						break;
					}
					else{
						x /= 10;
					}
				}
			}
			
		}
		System.out.println("");
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.*; util.* java class Main{
	public static void main(String[] args){
	int n =0;
	int x =0;
	Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		for(int i=1; i != n+1; i++){
			x = i;
			if(i%3 == 0){
				System.out.print(" "+i);
			}
			else{
				while(x != 0){
					if(x%10 == 3){
						System.out.print(" "+i);
						break;
					}
					else{
						x /= 10;
					}
				}
			}
			
		}
		System.out.println("");
	}
} Main public static void main(String[] args){
	int n =0;
	int x =0;
	Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		for(int i=1; i != n+1; i++){
			x = i;
			if(i%3 == 0){
				System.out.print(" "+i);
			}
			else{
				while(x != 0){
					if(x%10 == 3){
						System.out.print(" "+i);
						break;
					}
					else{
						x /= 10;
					}
				}
			}
			
		}
		System.out.println("");
	} main {
	int n =0;
	int x =0;
	Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		for(int i=1; i != n+1; i++){
			x = i;
			if(i%3 == 0){
				System.out.print(" "+i);
			}
			else{
				while(x != 0){
					if(x%10 == 3){
						System.out.print(" "+i);
						break;
					}
					else{
						x /= 10;
					}
				}
			}
			
		}
		System.out.println("");
	} int n =0; n 0 int x =0; x 0 Scanner scan = new Scanner(System.in); scan new Scanner(System.in) n = scan.nextInt() n scan.nextInt() scan.nextInt scan for(int i=1; i != n+1; i++){
			x = i;
			if(i%3 == 0){
				System.out.print(" "+i);
			}
			else{
				while(x != 0){
					if(x%10 == 3){
						System.out.print(" "+i);
						break;
					}
					else{
						x /= 10;
					}
				}
			}
			
		} int i=1; int i=1; i 1 i != n+1 i n+1 n 1 i++ i++ i {
			x = i;
			if(i%3 == 0){
				System.out.print(" "+i);
			}
			else{
				while(x != 0){
					if(x%10 == 3){
						System.out.print(" "+i);
						break;
					}
					else{
						x /= 10;
					}
				}
			}
			
		} {
			x = i;
			if(i%3 == 0){
				System.out.print(" "+i);
			}
			else{
				while(x != 0){
					if(x%10 == 3){
						System.out.print(" "+i);
						break;
					}
					else{
						x /= 10;
					}
				}
			}
			
		} x = i x i if(i%3 == 0){
				System.out.print(" "+i);
			}
			else{
				while(x != 0){
					if(x%10 == 3){
						System.out.print(" "+i);
						break;
					}
					else{
						x /= 10;
					}
				}
			} 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 {
				while(x != 0){
					if(x%10 == 3){
						System.out.print(" "+i);
						break;
					}
					else{
						x /= 10;
					}
				}
			} while(x != 0){
					if(x%10 == 3){
						System.out.print(" "+i);
						break;
					}
					else{
						x /= 10;
					}
				} 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.println("") System.out.println System.out System System.out "" String[] args args
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
class Main{
	public static void main(String[] args){
	int n =0;
	int x =0;
	Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		for(int i=1; i != n+1; i++){
			x = i;
			if(i%3 == 0){
				System.out.print(" "+i);
			}
			else{
				while(x != 0){
					if(x%10 == 3){
						System.out.print(" "+i);
						break;
					}
					else{
						x /= 10;
					}
				}
			}
			
		}
		System.out.println("");
	}
}