import java.util.Scanner;

public class Main {
	static StringBuilder text;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		text = new StringBuilder();
		scan.close();
		for(int i = 1;i <= n;i++){
			if(i % 3 == 0){
				text.append(" ").append(i);
			}else {
				if(process(i))
					text.append(" ").append(i);
			}
		}
		System.out.println(text.toString());
	}
	static boolean process(int i){
		if(i % 10 == 3){
			return true;
		}else{
			if(i / 10 == 0)
				return false;
			return process(i / 10);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	static StringBuilder text;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		text = new StringBuilder();
		scan.close();
		for(int i = 1;i <= n;i++){
			if(i % 3 == 0){
				text.append(" ").append(i);
			}else {
				if(process(i))
					text.append(" ").append(i);
			}
		}
		System.out.println(text.toString());
	}
	static boolean process(int i){
		if(i % 10 == 3){
			return true;
		}else{
			if(i / 10 == 0)
				return false;
			return process(i / 10);
		}
	}
} Main static StringBuilder text; text public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		text = new StringBuilder();
		scan.close();
		for(int i = 1;i <= n;i++){
			if(i % 3 == 0){
				text.append(" ").append(i);
			}else {
				if(process(i))
					text.append(" ").append(i);
			}
		}
		System.out.println(text.toString());
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		text = new StringBuilder();
		scan.close();
		for(int i = 1;i <= n;i++){
			if(i % 3 == 0){
				text.append(" ").append(i);
			}else {
				if(process(i))
					text.append(" ").append(i);
			}
		}
		System.out.println(text.toString());
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan text = new StringBuilder() text new StringBuilder() scan.close() scan.close scan for(int i = 1;i <= n;i++){
			if(i % 3 == 0){
				text.append(" ").append(i);
			}else {
				if(process(i))
					text.append(" ").append(i);
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if(i % 3 == 0){
				text.append(" ").append(i);
			}else {
				if(process(i))
					text.append(" ").append(i);
			}
		} {
			if(i % 3 == 0){
				text.append(" ").append(i);
			}else {
				if(process(i))
					text.append(" ").append(i);
			}
		} if(i % 3 == 0){
				text.append(" ").append(i);
			}else {
				if(process(i))
					text.append(" ").append(i);
			} i % 3 == 0 i % 3 i 3 0 {
				text.append(" ").append(i);
			} text.append(" ").append(i) text.append(" ").append text.append(" ") text.append text " " i {
				if(process(i))
					text.append(" ").append(i);
			} if(process(i))
					text.append(" ").append(i); process(i) process i text.append(" ").append(i) text.append(" ").append text.append(" ") text.append text " " i System.out.println(text.toString()) System.out.println System.out System System.out text.toString() text.toString text String[] args args static boolean process(int i){
		if(i % 10 == 3){
			return true;
		}else{
			if(i / 10 == 0)
				return false;
			return process(i / 10);
		}
	} process {
		if(i % 10 == 3){
			return true;
		}else{
			if(i / 10 == 0)
				return false;
			return process(i / 10);
		}
	} if(i % 10 == 3){
			return true;
		}else{
			if(i / 10 == 0)
				return false;
			return process(i / 10);
		} i % 10 == 3 i % 10 i 10 3 {
			return true;
		} return true; true {
			if(i / 10 == 0)
				return false;
			return process(i / 10);
		} if(i / 10 == 0)
				return false; i / 10 == 0 i / 10 i 10 0 return false; false return process(i / 10); process(i / 10) process i / 10 i 10 int i i public class Main {
	static StringBuilder text;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		text = new StringBuilder();
		scan.close();
		for(int i = 1;i <= n;i++){
			if(i % 3 == 0){
				text.append(" ").append(i);
			}else {
				if(process(i))
					text.append(" ").append(i);
			}
		}
		System.out.println(text.toString());
	}
	static boolean process(int i){
		if(i % 10 == 3){
			return true;
		}else{
			if(i / 10 == 0)
				return false;
			return process(i / 10);
		}
	}
} public class Main {
	static StringBuilder text;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		text = new StringBuilder();
		scan.close();
		for(int i = 1;i <= n;i++){
			if(i % 3 == 0){
				text.append(" ").append(i);
			}else {
				if(process(i))
					text.append(" ").append(i);
			}
		}
		System.out.println(text.toString());
	}
	static boolean process(int i){
		if(i % 10 == 3){
			return true;
		}else{
			if(i / 10 == 0)
				return false;
			return process(i / 10);
		}
	}
} Main
import java.util.Scanner;

public class Main {
	static StringBuilder text;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		text = new StringBuilder();
		scan.close();
		for(int i = 1;i <= n;i++){
			if(i % 3 == 0){
				text.append(" ").append(i);
			}else {
				if(process(i))
					text.append(" ").append(i);
			}
		}
		System.out.println(text.toString());
	}
	static boolean process(int i){
		if(i % 10 == 3){
			return true;
		}else{
			if(i / 10 == 0)
				return false;
			return process(i / 10);
		}
	}
}