import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		int i = 1;
		StringBuilder sb1 = new StringBuilder();
		for(i = 1 ; i <= n ; i++){
			int k = i;
			if(i%3 == 0 ){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 == 3){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 != 3 && i%3 != 0){
			for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			}
			}
			}
		System.out.println(sb1);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		int i = 1;
		StringBuilder sb1 = new StringBuilder();
		for(i = 1 ; i <= n ; i++){
			int k = i;
			if(i%3 == 0 ){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 == 3){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 != 3 && i%3 != 0){
			for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			}
			}
			}
		System.out.println(sb1);
	}
} Main public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		int i = 1;
		StringBuilder sb1 = new StringBuilder();
		for(i = 1 ; i <= n ; i++){
			int k = i;
			if(i%3 == 0 ){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 == 3){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 != 3 && i%3 != 0){
			for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			}
			}
			}
		System.out.println(sb1);
	} main {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		int i = 1;
		StringBuilder sb1 = new StringBuilder();
		for(i = 1 ; i <= n ; i++){
			int k = i;
			if(i%3 == 0 ){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 == 3){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 != 3 && i%3 != 0){
			for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			}
			}
			}
		System.out.println(sb1);
	} Scanner x = new Scanner(System.in); x new Scanner(System.in) int n = x.nextInt(); n x.nextInt() x.nextInt x int i = 1; i 1 StringBuilder sb1 = new StringBuilder(); sb1 new StringBuilder() for(i = 1 ; i <= n ; i++){
			int k = i;
			if(i%3 == 0 ){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 == 3){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 != 3 && i%3 != 0){
			for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			}
			}
			} i = 1 ; i = 1 i 1 i <= n i n i++ i++ i {
			int k = i;
			if(i%3 == 0 ){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 == 3){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 != 3 && i%3 != 0){
			for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			}
			}
			} {
			int k = i;
			if(i%3 == 0 ){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 == 3){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 != 3 && i%3 != 0){
			for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			}
			}
			} int k = i; k i if(i%3 == 0 ){
				sb1.append(" "+i);
				continue;
			} i%3 == 0 i%3 i 3 0 {
				sb1.append(" "+i);
				continue;
			} sb1.append(" "+i) sb1.append sb1 " "+i " " i continue; if(i%10 == 3){
				sb1.append(" "+i);
				continue;
			} i%10 == 3 i%10 i 10 3 {
				sb1.append(" "+i);
				continue;
			} sb1.append(" "+i) sb1.append sb1 " "+i " " i continue; if(i%10 != 3 && i%3 != 0){
			for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			}
			} i%10 != 3 && i%3 != 0 i%10 != 3 i%10 i 10 3 i%3 != 0 i%3 i 3 0 {
			for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			}
			} for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			} int m = 1; int m = 1; m 1 m <=3 m 3 m++ m++ m {
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			} {
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			} k /=10 k 10 if(k%10 == 3){
				sb1.append(" "+i);
				break;
			} k%10 == 3 k%10 k 10 3 {
				sb1.append(" "+i);
				break;
			} sb1.append(" "+i) sb1.append sb1 " "+i " " i break; System.out.println(sb1) System.out.println System.out System System.out sb1 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		int i = 1;
		StringBuilder sb1 = new StringBuilder();
		for(i = 1 ; i <= n ; i++){
			int k = i;
			if(i%3 == 0 ){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 == 3){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 != 3 && i%3 != 0){
			for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			}
			}
			}
		System.out.println(sb1);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		int i = 1;
		StringBuilder sb1 = new StringBuilder();
		for(i = 1 ; i <= n ; i++){
			int k = i;
			if(i%3 == 0 ){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 == 3){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 != 3 && i%3 != 0){
			for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			}
			}
			}
		System.out.println(sb1);
	}
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		int i = 1;
		StringBuilder sb1 = new StringBuilder();
		for(i = 1 ; i <= n ; i++){
			int k = i;
			if(i%3 == 0 ){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 == 3){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 != 3 && i%3 != 0){
			for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			}
			}
			}
		System.out.println(sb1);
	}
}