import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int a =1;a<=n;a++){
			String s = String.valueOf(a);
			if(a%3 == 0){
				System.out.print(" "+a);
			}else{
				int t = s.indexOf("3");
				if(t != -1){
					System.out.print(" "+a);
				}
			}
		}
		System.out.println("");
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int a =1;a<=n;a++){
			String s = String.valueOf(a);
			if(a%3 == 0){
				System.out.print(" "+a);
			}else{
				int t = s.indexOf("3");
				if(t != -1){
					System.out.print(" "+a);
				}
			}
		}
		System.out.println("");
	}
} Main public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int a =1;a<=n;a++){
			String s = String.valueOf(a);
			if(a%3 == 0){
				System.out.print(" "+a);
			}else{
				int t = s.indexOf("3");
				if(t != -1){
					System.out.print(" "+a);
				}
			}
		}
		System.out.println("");
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int a =1;a<=n;a++){
			String s = String.valueOf(a);
			if(a%3 == 0){
				System.out.print(" "+a);
			}else{
				int t = s.indexOf("3");
				if(t != -1){
					System.out.print(" "+a);
				}
			}
		}
		System.out.println("");
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan for(int a =1;a<=n;a++){
			String s = String.valueOf(a);
			if(a%3 == 0){
				System.out.print(" "+a);
			}else{
				int t = s.indexOf("3");
				if(t != -1){
					System.out.print(" "+a);
				}
			}
		} int a =1; int a =1; a 1 a<=n a n a++ a++ a {
			String s = String.valueOf(a);
			if(a%3 == 0){
				System.out.print(" "+a);
			}else{
				int t = s.indexOf("3");
				if(t != -1){
					System.out.print(" "+a);
				}
			}
		} {
			String s = String.valueOf(a);
			if(a%3 == 0){
				System.out.print(" "+a);
			}else{
				int t = s.indexOf("3");
				if(t != -1){
					System.out.print(" "+a);
				}
			}
		} String s = String.valueOf(a); s String.valueOf(a) String.valueOf String a if(a%3 == 0){
				System.out.print(" "+a);
			}else{
				int t = s.indexOf("3");
				if(t != -1){
					System.out.print(" "+a);
				}
			} a%3 == 0 a%3 a 3 0 {
				System.out.print(" "+a);
			} System.out.print(" "+a) System.out.print System.out System System.out " "+a " " a {
				int t = s.indexOf("3");
				if(t != -1){
					System.out.print(" "+a);
				}
			} int t = s.indexOf("3"); t s.indexOf("3") s.indexOf s "3" if(t != -1){
					System.out.print(" "+a);
				} t != -1 t -1 1 {
					System.out.print(" "+a);
				} System.out.print(" "+a) System.out.print System.out System System.out " "+a " " a System.out.println("") System.out.println System.out System System.out "" String[] args args public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int a =1;a<=n;a++){
			String s = String.valueOf(a);
			if(a%3 == 0){
				System.out.print(" "+a);
			}else{
				int t = s.indexOf("3");
				if(t != -1){
					System.out.print(" "+a);
				}
			}
		}
		System.out.println("");
	}
} public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int a =1;a<=n;a++){
			String s = String.valueOf(a);
			if(a%3 == 0){
				System.out.print(" "+a);
			}else{
				int t = s.indexOf("3");
				if(t != -1){
					System.out.print(" "+a);
				}
			}
		}
		System.out.println("");
	}
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int a =1;a<=n;a++){
			String s = String.valueOf(a);
			if(a%3 == 0){
				System.out.print(" "+a);
			}else{
				int t = s.indexOf("3");
				if(t != -1){
					System.out.print(" "+a);
				}
			}
		}
		System.out.println("");
	}
}