import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		int data = Integer.parseInt(reader.readLine());
		
		for(int i=1; i<=data; i++){
			if(i%3==0){
				builder.append(" ").append(Integer.toString(i));
				continue;
			}
			int x=i;
			do{
				if(x%10==3){
					builder.append(" ").append(Integer.toString(i));
					break;
				}
				x/=10;
			}while(x!=0);
		}
		
		System.out.println(builder);
		
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String args[]) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		int data = Integer.parseInt(reader.readLine());
		
		for(int i=1; i<=data; i++){
			if(i%3==0){
				builder.append(" ").append(Integer.toString(i));
				continue;
			}
			int x=i;
			do{
				if(x%10==3){
					builder.append(" ").append(Integer.toString(i));
					break;
				}
				x/=10;
			}while(x!=0);
		}
		
		System.out.println(builder);
		
	}
} Main public static void main(String args[]) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		int data = Integer.parseInt(reader.readLine());
		
		for(int i=1; i<=data; i++){
			if(i%3==0){
				builder.append(" ").append(Integer.toString(i));
				continue;
			}
			int x=i;
			do{
				if(x%10==3){
					builder.append(" ").append(Integer.toString(i));
					break;
				}
				x/=10;
			}while(x!=0);
		}
		
		System.out.println(builder);
		
	} main {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		int data = Integer.parseInt(reader.readLine());
		
		for(int i=1; i<=data; i++){
			if(i%3==0){
				builder.append(" ").append(Integer.toString(i));
				continue;
			}
			int x=i;
			do{
				if(x%10==3){
					builder.append(" ").append(Integer.toString(i));
					break;
				}
				x/=10;
			}while(x!=0);
		}
		
		System.out.println(builder);
		
	} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) StringBuilder builder = new StringBuilder(); builder new StringBuilder() int data = Integer.parseInt(reader.readLine()); data Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader for(int i=1; i<=data; i++){
			if(i%3==0){
				builder.append(" ").append(Integer.toString(i));
				continue;
			}
			int x=i;
			do{
				if(x%10==3){
					builder.append(" ").append(Integer.toString(i));
					break;
				}
				x/=10;
			}while(x!=0);
		} int i=1; int i=1; i 1 i<=data i data i++ i++ i {
			if(i%3==0){
				builder.append(" ").append(Integer.toString(i));
				continue;
			}
			int x=i;
			do{
				if(x%10==3){
					builder.append(" ").append(Integer.toString(i));
					break;
				}
				x/=10;
			}while(x!=0);
		} {
			if(i%3==0){
				builder.append(" ").append(Integer.toString(i));
				continue;
			}
			int x=i;
			do{
				if(x%10==3){
					builder.append(" ").append(Integer.toString(i));
					break;
				}
				x/=10;
			}while(x!=0);
		} if(i%3==0){
				builder.append(" ").append(Integer.toString(i));
				continue;
			} i%3==0 i%3 i 3 0 {
				builder.append(" ").append(Integer.toString(i));
				continue;
			} builder.append(" ").append(Integer.toString(i)) builder.append(" ").append builder.append(" ") builder.append builder " " Integer.toString(i) Integer.toString Integer i continue; int x=i; x i do{
				if(x%10==3){
					builder.append(" ").append(Integer.toString(i));
					break;
				}
				x/=10;
			}while(x!=0); x!=0 x 0 {
				if(x%10==3){
					builder.append(" ").append(Integer.toString(i));
					break;
				}
				x/=10;
			} if(x%10==3){
					builder.append(" ").append(Integer.toString(i));
					break;
				} x%10==3 x%10 x 10 3 {
					builder.append(" ").append(Integer.toString(i));
					break;
				} builder.append(" ").append(Integer.toString(i)) builder.append(" ").append builder.append(" ") builder.append builder " " Integer.toString(i) Integer.toString Integer i break; x/=10 x 10 System.out.println(builder) System.out.println System.out System System.out builder String args[] args public class Main {
	public static void main(String args[]) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		int data = Integer.parseInt(reader.readLine());
		
		for(int i=1; i<=data; i++){
			if(i%3==0){
				builder.append(" ").append(Integer.toString(i));
				continue;
			}
			int x=i;
			do{
				if(x%10==3){
					builder.append(" ").append(Integer.toString(i));
					break;
				}
				x/=10;
			}while(x!=0);
		}
		
		System.out.println(builder);
		
	}
} public class Main {
	public static void main(String args[]) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		int data = Integer.parseInt(reader.readLine());
		
		for(int i=1; i<=data; i++){
			if(i%3==0){
				builder.append(" ").append(Integer.toString(i));
				continue;
			}
			int x=i;
			do{
				if(x%10==3){
					builder.append(" ").append(Integer.toString(i));
					break;
				}
				x/=10;
			}while(x!=0);
		}
		
		System.out.println(builder);
		
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		int data = Integer.parseInt(reader.readLine());
		
		for(int i=1; i<=data; i++){
			if(i%3==0){
				builder.append(" ").append(Integer.toString(i));
				continue;
			}
			int x=i;
			do{
				if(x%10==3){
					builder.append(" ").append(Integer.toString(i));
					break;
				}
				x/=10;
			}while(x!=0);
		}
		
		System.out.println(builder);
		
	}
}