import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		String line;
		int n;

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		try {
			line = reader.readLine();
			n = Integer.parseInt(line);

			for(int i=1;i<=n;i++){
				if(i%3==0){
					System.out.print(" "+i);
				}
				else if(String.valueOf(i).contains("3")){
					System.out.print(" "+i);
				}
			}
			System.out.println();
		} catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) {
		String line;
		int n;

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		try {
			line = reader.readLine();
			n = Integer.parseInt(line);

			for(int i=1;i<=n;i++){
				if(i%3==0){
					System.out.print(" "+i);
				}
				else if(String.valueOf(i).contains("3")){
					System.out.print(" "+i);
				}
			}
			System.out.println();
		} catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}
	}
} Main public static void main(String[] args) {
		String line;
		int n;

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		try {
			line = reader.readLine();
			n = Integer.parseInt(line);

			for(int i=1;i<=n;i++){
				if(i%3==0){
					System.out.print(" "+i);
				}
				else if(String.valueOf(i).contains("3")){
					System.out.print(" "+i);
				}
			}
			System.out.println();
		} catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}
	} main {
		String line;
		int n;

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		try {
			line = reader.readLine();
			n = Integer.parseInt(line);

			for(int i=1;i<=n;i++){
				if(i%3==0){
					System.out.print(" "+i);
				}
				else if(String.valueOf(i).contains("3")){
					System.out.print(" "+i);
				}
			}
			System.out.println();
		} catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}
	} String line; line int n; n BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in)); reader new BufferedReader(new InputStreamReader(
				System.in)) try {
			line = reader.readLine();
			n = Integer.parseInt(line);

			for(int i=1;i<=n;i++){
				if(i%3==0){
					System.out.print(" "+i);
				}
				else if(String.valueOf(i).contains("3")){
					System.out.print(" "+i);
				}
			}
			System.out.println();
		} catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		} catch (NumberFormatException e) {
			System.out.println(e);
		} NumberFormatException e {
			System.out.println(e);
		} System.out.println(e) System.out.println System.out System System.out e catch (IOException e) {
			System.out.println(e);
		} IOException e {
			System.out.println(e);
		} System.out.println(e) System.out.println System.out System System.out e {
			line = reader.readLine();
			n = Integer.parseInt(line);

			for(int i=1;i<=n;i++){
				if(i%3==0){
					System.out.print(" "+i);
				}
				else if(String.valueOf(i).contains("3")){
					System.out.print(" "+i);
				}
			}
			System.out.println();
		} line = reader.readLine() line reader.readLine() reader.readLine reader n = Integer.parseInt(line) n Integer.parseInt(line) Integer.parseInt Integer line for(int i=1;i<=n;i++){
				if(i%3==0){
					System.out.print(" "+i);
				}
				else if(String.valueOf(i).contains("3")){
					System.out.print(" "+i);
				}
			} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
				if(i%3==0){
					System.out.print(" "+i);
				}
				else if(String.valueOf(i).contains("3")){
					System.out.print(" "+i);
				}
			} {
				if(i%3==0){
					System.out.print(" "+i);
				}
				else if(String.valueOf(i).contains("3")){
					System.out.print(" "+i);
				}
			} if(i%3==0){
					System.out.print(" "+i);
				}
				else if(String.valueOf(i).contains("3")){
					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 if(String.valueOf(i).contains("3")){
					System.out.print(" "+i);
				} String.valueOf(i).contains("3") String.valueOf(i).contains String.valueOf(i) String.valueOf String i "3" {
					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) {
		String line;
		int n;

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		try {
			line = reader.readLine();
			n = Integer.parseInt(line);

			for(int i=1;i<=n;i++){
				if(i%3==0){
					System.out.print(" "+i);
				}
				else if(String.valueOf(i).contains("3")){
					System.out.print(" "+i);
				}
			}
			System.out.println();
		} catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}
	}
} public class Main {
	public static void main(String[] args) {
		String line;
		int n;

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		try {
			line = reader.readLine();
			n = Integer.parseInt(line);

			for(int i=1;i<=n;i++){
				if(i%3==0){
					System.out.print(" "+i);
				}
				else if(String.valueOf(i).contains("3")){
					System.out.print(" "+i);
				}
			}
			System.out.println();
		} catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		String line;
		int n;

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		try {
			line = reader.readLine();
			n = Integer.parseInt(line);

			for(int i=1;i<=n;i++){
				if(i%3==0){
					System.out.print(" "+i);
				}
				else if(String.valueOf(i).contains("3")){
					System.out.print(" "+i);
				}
			}
			System.out.println();
		} catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}
	}
}