import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i=1;
		int a;
		while(true){
			if(i%3==0){
				System.out.printf(" %d", i);
			}else{
				a=i;
				while(true){ 
					if(a%10==3){
					System.out.printf(" %d", i);
					break;
					}
					a/=10;
					if(a==0){
						break;
					}
				}
			}
			if(i==n){
				System.out.println();
				break;
			}
			i++;

		}
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i=1;
		int a;
		while(true){
			if(i%3==0){
				System.out.printf(" %d", i);
			}else{
				a=i;
				while(true){ 
					if(a%10==3){
					System.out.printf(" %d", i);
					break;
					}
					a/=10;
					if(a==0){
						break;
					}
				}
			}
			if(i==n){
				System.out.println();
				break;
			}
			i++;

		}
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i=1;
		int a;
		while(true){
			if(i%3==0){
				System.out.printf(" %d", i);
			}else{
				a=i;
				while(true){ 
					if(a%10==3){
					System.out.printf(" %d", i);
					break;
					}
					a/=10;
					if(a==0){
						break;
					}
				}
			}
			if(i==n){
				System.out.println();
				break;
			}
			i++;

		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i=1;
		int a;
		while(true){
			if(i%3==0){
				System.out.printf(" %d", i);
			}else{
				a=i;
				while(true){ 
					if(a%10==3){
					System.out.printf(" %d", i);
					break;
					}
					a/=10;
					if(a==0){
						break;
					}
				}
			}
			if(i==n){
				System.out.println();
				break;
			}
			i++;

		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int i=1; i 1 int a; a while(true){
			if(i%3==0){
				System.out.printf(" %d", i);
			}else{
				a=i;
				while(true){ 
					if(a%10==3){
					System.out.printf(" %d", i);
					break;
					}
					a/=10;
					if(a==0){
						break;
					}
				}
			}
			if(i==n){
				System.out.println();
				break;
			}
			i++;

		} true {
			if(i%3==0){
				System.out.printf(" %d", i);
			}else{
				a=i;
				while(true){ 
					if(a%10==3){
					System.out.printf(" %d", i);
					break;
					}
					a/=10;
					if(a==0){
						break;
					}
				}
			}
			if(i==n){
				System.out.println();
				break;
			}
			i++;

		} if(i%3==0){
				System.out.printf(" %d", i);
			}else{
				a=i;
				while(true){ 
					if(a%10==3){
					System.out.printf(" %d", i);
					break;
					}
					a/=10;
					if(a==0){
						break;
					}
				}
			} i%3==0 i%3 i 3 0 {
				System.out.printf(" %d", i);
			} System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i {
				a=i;
				while(true){ 
					if(a%10==3){
					System.out.printf(" %d", i);
					break;
					}
					a/=10;
					if(a==0){
						break;
					}
				}
			} a=i a i while(true){ 
					if(a%10==3){
					System.out.printf(" %d", i);
					break;
					}
					a/=10;
					if(a==0){
						break;
					}
				} true { 
					if(a%10==3){
					System.out.printf(" %d", i);
					break;
					}
					a/=10;
					if(a==0){
						break;
					}
				} if(a%10==3){
					System.out.printf(" %d", i);
					break;
					} a%10==3 a%10 a 10 3 {
					System.out.printf(" %d", i);
					break;
					} System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i break; a/=10 a 10 if(a==0){
						break;
					} a==0 a 0 {
						break;
					} break; if(i==n){
				System.out.println();
				break;
			} i==n i n {
				System.out.println();
				break;
			} System.out.println() System.out.println System.out System System.out break; i++ i String[] args args public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i=1;
		int a;
		while(true){
			if(i%3==0){
				System.out.printf(" %d", i);
			}else{
				a=i;
				while(true){ 
					if(a%10==3){
					System.out.printf(" %d", i);
					break;
					}
					a/=10;
					if(a==0){
						break;
					}
				}
			}
			if(i==n){
				System.out.println();
				break;
			}
			i++;

		}
	}
} public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i=1;
		int a;
		while(true){
			if(i%3==0){
				System.out.printf(" %d", i);
			}else{
				a=i;
				while(true){ 
					if(a%10==3){
					System.out.printf(" %d", i);
					break;
					}
					a/=10;
					if(a==0){
						break;
					}
				}
			}
			if(i==n){
				System.out.println();
				break;
			}
			i++;

		}
	}
} Main
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i=1;
		int a;
		while(true){
			if(i%3==0){
				System.out.printf(" %d", i);
			}else{
				a=i;
				while(true){ 
					if(a%10==3){
					System.out.printf(" %d", i);
					break;
					}
					a/=10;
					if(a==0){
						break;
					}
				}
			}
			if(i==n){
				System.out.println();
				break;
			}
			i++;

		}
	}
}