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