
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		for (int i = 3; i <= a; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3"))
				System.out.print(" " + i);
		}
		System.out.println();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		for (int i = 3; i <= a; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3"))
				System.out.print(" " + i);
		}
		System.out.println();
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		for (int i = 3; i <= a; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3"))
				System.out.print(" " + i);
		}
		System.out.println();
	} main {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		for (int i = 3; i <= a; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3"))
				System.out.print(" " + i);
		}
		System.out.println();
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int a = scanner.nextInt(); a scanner.nextInt() scanner.nextInt scanner for (int i = 3; i <= a; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3"))
				System.out.print(" " + i);
		} int i = 3; int i = 3; i 3 i <= a i a i++ i++ i {
			if (i % 3 == 0 || String.valueOf(i).contains("3"))
				System.out.print(" " + i);
		} {
			if (i % 3 == 0 || String.valueOf(i).contains("3"))
				System.out.print(" " + i);
		} if (i % 3 == 0 || String.valueOf(i).contains("3"))
				System.out.print(" " + i); i % 3 == 0 || String.valueOf(i).contains("3") i % 3 == 0 i % 3 i 3 0 String.valueOf(i).contains("3") String.valueOf(i).contains String.valueOf(i) String.valueOf String i "3" 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) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		for (int i = 3; i <= a; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3"))
				System.out.print(" " + i);
		}
		System.out.println();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		for (int i = 3; i <= a; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3"))
				System.out.print(" " + i);
		}
		System.out.println();
	}
} Main

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		for (int i = 3; i <= a; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3"))
				System.out.print(" " + i);
		}
		System.out.println();
	}
}