import java.util.*;

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

class Main{
	public static void main(String[] args){
		Scanner sr = new Scanner(System.in);
		int in = sr.nextInt();
		int x;
		for(int i=1;i<=in;i++){
			if(i%3==0){
				System.out.print(" "+i);
			}else if(i%10==3){
				System.out.print(" "+i);
			}else{
					x = i/10;
				while(x!=0){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}else{
						x = x/10;
					}
				}
			}
		}
		System.out.println();
	}
}