import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				boolean include3 = false;
				
				do {
					if (x % 10 == 3)
						include3 = true;
					x /= 10;
				} while (x > 0);
				
				if (include3)
					System.out.print(" " + i);
			}
		}
		System.out.println();
	}

}
 import java.util.Scanner; Scanner java.util class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				boolean include3 = false;
				
				do {
					if (x % 10 == 3)
						include3 = true;
					x /= 10;
				} while (x > 0);
				
				if (include3)
					System.out.print(" " + i);
			}
		}
		System.out.println();
	}

} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				boolean include3 = false;
				
				do {
					if (x % 10 == 3)
						include3 = true;
					x /= 10;
				} while (x > 0);
				
				if (include3)
					System.out.print(" " + i);
			}
		}
		System.out.println();
	} main {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				boolean include3 = false;
				
				do {
					if (x % 10 == 3)
						include3 = true;
					x /= 10;
				} while (x > 0);
				
				if (include3)
					System.out.print(" " + i);
			}
		}
		System.out.println();
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				boolean include3 = false;
				
				do {
					if (x % 10 == 3)
						include3 = true;
					x /= 10;
				} while (x > 0);
				
				if (include3)
					System.out.print(" " + i);
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				boolean include3 = false;
				
				do {
					if (x % 10 == 3)
						include3 = true;
					x /= 10;
				} while (x > 0);
				
				if (include3)
					System.out.print(" " + i);
			}
		} {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				boolean include3 = false;
				
				do {
					if (x % 10 == 3)
						include3 = true;
					x /= 10;
				} while (x > 0);
				
				if (include3)
					System.out.print(" " + i);
			}
		} int x = i; x i if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				boolean include3 = false;
				
				do {
					if (x % 10 == 3)
						include3 = true;
					x /= 10;
				} while (x > 0);
				
				if (include3)
					System.out.print(" " + i);
			} x % 3 == 0 x % 3 x 3 0 {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
				boolean include3 = false;
				
				do {
					if (x % 10 == 3)
						include3 = true;
					x /= 10;
				} while (x > 0);
				
				if (include3)
					System.out.print(" " + i);
			} boolean include3 = false; include3 false do {
					if (x % 10 == 3)
						include3 = true;
					x /= 10;
				} while (x > 0); x > 0 x 0 {
					if (x % 10 == 3)
						include3 = true;
					x /= 10;
				} if (x % 10 == 3)
						include3 = true; x % 10 == 3 x % 10 x 10 3 include3 = true include3 true x /= 10 x 10 if (include3)
					System.out.print(" " + i); include3 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
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				boolean include3 = false;
				
				do {
					if (x % 10 == 3)
						include3 = true;
					x /= 10;
				} while (x > 0);
				
				if (include3)
					System.out.print(" " + i);
			}
		}
		System.out.println();
	}

}

