import java.util.*;

class Main{
	public static void main(String args[]){
		int num = 3;
		int x;
		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		x = scan.nextInt();

		while(true){
			if(x < num){
				break;
			}
			if(num % 3 == 0 || Integer.toString(num).contains("3")){
				sb.append(" " + num);
			}
			num++;
		}
		System.out.println(sb);
	}
} import java.util.*; util.* java class Main{
	public static void main(String args[]){
		int num = 3;
		int x;
		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		x = scan.nextInt();

		while(true){
			if(x < num){
				break;
			}
			if(num % 3 == 0 || Integer.toString(num).contains("3")){
				sb.append(" " + num);
			}
			num++;
		}
		System.out.println(sb);
	}
} Main public static void main(String args[]){
		int num = 3;
		int x;
		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		x = scan.nextInt();

		while(true){
			if(x < num){
				break;
			}
			if(num % 3 == 0 || Integer.toString(num).contains("3")){
				sb.append(" " + num);
			}
			num++;
		}
		System.out.println(sb);
	} main {
		int num = 3;
		int x;
		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		x = scan.nextInt();

		while(true){
			if(x < num){
				break;
			}
			if(num % 3 == 0 || Integer.toString(num).contains("3")){
				sb.append(" " + num);
			}
			num++;
		}
		System.out.println(sb);
	} int num = 3; num 3 int x; x Scanner scan = new Scanner(System.in); scan new Scanner(System.in) StringBuffer sb = new StringBuffer(); sb new StringBuffer() x = scan.nextInt() x scan.nextInt() scan.nextInt scan while(true){
			if(x < num){
				break;
			}
			if(num % 3 == 0 || Integer.toString(num).contains("3")){
				sb.append(" " + num);
			}
			num++;
		} true {
			if(x < num){
				break;
			}
			if(num % 3 == 0 || Integer.toString(num).contains("3")){
				sb.append(" " + num);
			}
			num++;
		} if(x < num){
				break;
			} x < num x num {
				break;
			} break; if(num % 3 == 0 || Integer.toString(num).contains("3")){
				sb.append(" " + num);
			} num % 3 == 0 || Integer.toString(num).contains("3") num % 3 == 0 num % 3 num 3 0 Integer.toString(num).contains("3") Integer.toString(num).contains Integer.toString(num) Integer.toString Integer num "3" {
				sb.append(" " + num);
			} sb.append(" " + num) sb.append sb " " + num " " num num++ num System.out.println(sb) System.out.println System.out System System.out sb String args[] args
import java.util.*;

class Main{
	public static void main(String args[]){
		int num = 3;
		int x;
		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		x = scan.nextInt();

		while(true){
			if(x < num){
				break;
			}
			if(num % 3 == 0 || Integer.toString(num).contains("3")){
				sb.append(" " + num);
			}
			num++;
		}
		System.out.println(sb);
	}
}