import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		
		for(int i = 3; i <= n; i++){
			
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else{
				//String??????????????????1????????\??????char'3'????????????
				String strNum = String.valueOf(i);
				//???????????????boolean??§??????
				boolean isMatch = false;
				for(int j = 0; j < strNum.length(); j++){
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				}
				if(isMatch){
					//ture?????´???????????????????????§??¨?????????
					System.out.print(" " + i);					
				}
			}
		} 
		System.out.println();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		
		for(int i = 3; i <= n; i++){
			
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else{
				//String??????????????????1????????\??????char'3'????????????
				String strNum = String.valueOf(i);
				//???????????????boolean??§??????
				boolean isMatch = false;
				for(int j = 0; j < strNum.length(); j++){
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				}
				if(isMatch){
					//ture?????´???????????????????????§??¨?????????
					System.out.print(" " + i);					
				}
			}
		} 
		System.out.println();
	}
} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		
		for(int i = 3; i <= n; i++){
			
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else{
				//String??????????????????1????????\??????char'3'????????????
				String strNum = String.valueOf(i);
				//???????????????boolean??§??????
				boolean isMatch = false;
				for(int j = 0; j < strNum.length(); j++){
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				}
				if(isMatch){
					//ture?????´???????????????????????§??¨?????????
					System.out.print(" " + i);					
				}
			}
		} 
		System.out.println();
	} main {
		// TODO ?????????????????????????????????????????????
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		
		for(int i = 3; i <= n; i++){
			
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else{
				//String??????????????????1????????\??????char'3'????????????
				String strNum = String.valueOf(i);
				//???????????????boolean??§??????
				boolean isMatch = false;
				for(int j = 0; j < strNum.length(); j++){
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				}
				if(isMatch){
					//ture?????´???????????????????????§??¨?????????
					System.out.print(" " + i);					
				}
			}
		} 
		System.out.println();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan scan.close() scan.close scan for(int i = 3; i <= n; i++){
			
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else{
				//String??????????????????1????????\??????char'3'????????????
				String strNum = String.valueOf(i);
				//???????????????boolean??§??????
				boolean isMatch = false;
				for(int j = 0; j < strNum.length(); j++){
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				}
				if(isMatch){
					//ture?????´???????????????????????§??¨?????????
					System.out.print(" " + i);					
				}
			}
		} int i = 3; int i = 3; i 3 i <= n i n i++ i++ i {
			
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else{
				//String??????????????????1????????\??????char'3'????????????
				String strNum = String.valueOf(i);
				//???????????????boolean??§??????
				boolean isMatch = false;
				for(int j = 0; j < strNum.length(); j++){
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				}
				if(isMatch){
					//ture?????´???????????????????????§??¨?????????
					System.out.print(" " + i);					
				}
			}
		} {
			
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else{
				//String??????????????????1????????\??????char'3'????????????
				String strNum = String.valueOf(i);
				//???????????????boolean??§??????
				boolean isMatch = false;
				for(int j = 0; j < strNum.length(); j++){
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				}
				if(isMatch){
					//ture?????´???????????????????????§??¨?????????
					System.out.print(" " + i);					
				}
			}
		} if(i % 3 == 0){
				System.out.print(" " + i);
			}else{
				//String??????????????????1????????\??????char'3'????????????
				String strNum = String.valueOf(i);
				//???????????????boolean??§??????
				boolean isMatch = false;
				for(int j = 0; j < strNum.length(); j++){
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				}
				if(isMatch){
					//ture?????´???????????????????????§??¨?????????
					System.out.print(" " + i);					
				}
			} i % 3 == 0 i % 3 i 3 0 {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
				//String??????????????????1????????\??????char'3'????????????
				String strNum = String.valueOf(i);
				//???????????????boolean??§??????
				boolean isMatch = false;
				for(int j = 0; j < strNum.length(); j++){
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				}
				if(isMatch){
					//ture?????´???????????????????????§??¨?????????
					System.out.print(" " + i);					
				}
			} String strNum = String.valueOf(i); strNum String.valueOf(i) String.valueOf String i boolean isMatch = false; isMatch false for(int j = 0; j < strNum.length(); j++){
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				} int j = 0; int j = 0; j 0 j < strNum.length() j strNum.length() strNum.length strNum j++ j++ j {
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				} {
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				} char x = strNum.charAt(j); x strNum.charAt(j) strNum.charAt strNum j if(x == '3'){
						isMatch = true;
					} x == '3' x '3' {
						isMatch = true;
					} isMatch = true isMatch true if(isMatch){
					//ture?????´???????????????????????§??¨?????????
					System.out.print(" " + i);					
				} isMatch {
					//ture?????´???????????????????????§??¨?????????
					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 class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		
		for(int i = 3; i <= n; i++){
			
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else{
				//String??????????????????1????????\??????char'3'????????????
				String strNum = String.valueOf(i);
				//???????????????boolean??§??????
				boolean isMatch = false;
				for(int j = 0; j < strNum.length(); j++){
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				}
				if(isMatch){
					//ture?????´???????????????????????§??¨?????????
					System.out.print(" " + i);					
				}
			}
		} 
		System.out.println();
	}
} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		
		for(int i = 3; i <= n; i++){
			
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else{
				//String??????????????????1????????\??????char'3'????????????
				String strNum = String.valueOf(i);
				//???????????????boolean??§??????
				boolean isMatch = false;
				for(int j = 0; j < strNum.length(); j++){
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				}
				if(isMatch){
					//ture?????´???????????????????????§??¨?????????
					System.out.print(" " + i);					
				}
			}
		} 
		System.out.println();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		
		for(int i = 3; i <= n; i++){
			
			if(i % 3 == 0){
				System.out.print(" " + i);
			}else{
				//String??????????????????1????????\??????char'3'????????????
				String strNum = String.valueOf(i);
				//???????????????boolean??§??????
				boolean isMatch = false;
				for(int j = 0; j < strNum.length(); j++){
					//for?????§??¨?????????????????????boolean??§??????					
					char x = strNum.charAt(j);
					if(x == '3'){
						isMatch = true;
					}
				}
				if(isMatch){
					//ture?????´???????????????????????§??¨?????????
					System.out.print(" " + i);					
				}
			}
		} 
		System.out.println();
	}
}