import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	    
		int n = sc.nextInt();
		
		for (int i = 1; i <= n; i++){
			if ((i % 3 == 0) || (i % 10 == 3) || include3(i / 10)){
					System.out.print(" "+ i);
			}
		}
		System.out.println("");
	}
	
	public static boolean include3(int num){
		boolean flg = false;
		String s = Integer.toString(num);
		for (int i = 0; i < s.length(); i++){
			if (s.charAt(i) == '3'){
				flg = true;
			}
		}
		return flg;
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	    
		int n = sc.nextInt();
		
		for (int i = 1; i <= n; i++){
			if ((i % 3 == 0) || (i % 10 == 3) || include3(i / 10)){
					System.out.print(" "+ i);
			}
		}
		System.out.println("");
	}
	
	public static boolean include3(int num){
		boolean flg = false;
		String s = Integer.toString(num);
		for (int i = 0; i < s.length(); i++){
			if (s.charAt(i) == '3'){
				flg = true;
			}
		}
		return flg;
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	    
		int n = sc.nextInt();
		
		for (int i = 1; i <= n; i++){
			if ((i % 3 == 0) || (i % 10 == 3) || include3(i / 10)){
					System.out.print(" "+ i);
			}
		}
		System.out.println("");
	} main {
		Scanner sc = new Scanner(System.in);
	    
		int n = sc.nextInt();
		
		for (int i = 1; i <= n; i++){
			if ((i % 3 == 0) || (i % 10 == 3) || include3(i / 10)){
					System.out.print(" "+ i);
			}
		}
		System.out.println("");
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc for (int i = 1; i <= n; i++){
			if ((i % 3 == 0) || (i % 10 == 3) || include3(i / 10)){
					System.out.print(" "+ i);
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if ((i % 3 == 0) || (i % 10 == 3) || include3(i / 10)){
					System.out.print(" "+ i);
			}
		} {
			if ((i % 3 == 0) || (i % 10 == 3) || include3(i / 10)){
					System.out.print(" "+ i);
			}
		} if ((i % 3 == 0) || (i % 10 == 3) || include3(i / 10)){
					System.out.print(" "+ i);
			} (i % 3 == 0) || (i % 10 == 3) || include3(i / 10) (i % 3 == 0) || (i % 10 == 3) || include3(i / 10) (i % 3 == 0) i % 3 i 3 0 (i % 10 == 3) i % 10 i 10 3 include3(i / 10) include3 i / 10 i 10 {
					System.out.print(" "+ i);
			} System.out.print(" "+ i) System.out.print System.out System System.out " "+ i " " i System.out.println("") System.out.println System.out System System.out "" String[] args args public static boolean include3(int num){
		boolean flg = false;
		String s = Integer.toString(num);
		for (int i = 0; i < s.length(); i++){
			if (s.charAt(i) == '3'){
				flg = true;
			}
		}
		return flg;
	} include3 {
		boolean flg = false;
		String s = Integer.toString(num);
		for (int i = 0; i < s.length(); i++){
			if (s.charAt(i) == '3'){
				flg = true;
			}
		}
		return flg;
	} boolean flg = false; flg false String s = Integer.toString(num); s Integer.toString(num) Integer.toString Integer num for (int i = 0; i < s.length(); i++){
			if (s.charAt(i) == '3'){
				flg = true;
			}
		} int i = 0; int i = 0; i 0 i < s.length() i s.length() s.length s i++ i++ i {
			if (s.charAt(i) == '3'){
				flg = true;
			}
		} {
			if (s.charAt(i) == '3'){
				flg = true;
			}
		} if (s.charAt(i) == '3'){
				flg = true;
			} s.charAt(i) == '3' s.charAt(i) s.charAt s i '3' {
				flg = true;
			} flg = true flg true return flg; flg int num num public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	    
		int n = sc.nextInt();
		
		for (int i = 1; i <= n; i++){
			if ((i % 3 == 0) || (i % 10 == 3) || include3(i / 10)){
					System.out.print(" "+ i);
			}
		}
		System.out.println("");
	}
	
	public static boolean include3(int num){
		boolean flg = false;
		String s = Integer.toString(num);
		for (int i = 0; i < s.length(); i++){
			if (s.charAt(i) == '3'){
				flg = true;
			}
		}
		return flg;
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	    
		int n = sc.nextInt();
		
		for (int i = 1; i <= n; i++){
			if ((i % 3 == 0) || (i % 10 == 3) || include3(i / 10)){
					System.out.print(" "+ i);
			}
		}
		System.out.println("");
	}
	
	public static boolean include3(int num){
		boolean flg = false;
		String s = Integer.toString(num);
		for (int i = 0; i < s.length(); i++){
			if (s.charAt(i) == '3'){
				flg = true;
			}
		}
		return flg;
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	    
		int n = sc.nextInt();
		
		for (int i = 1; i <= n; i++){
			if ((i % 3 == 0) || (i % 10 == 3) || include3(i / 10)){
					System.out.print(" "+ i);
			}
		}
		System.out.println("");
	}
	
	public static boolean include3(int num){
		boolean flg = false;
		String s = Integer.toString(num);
		for (int i = 0; i < s.length(); i++){
			if (s.charAt(i) == '3'){
				flg = true;
			}
		}
		return flg;
	}
}