
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		for (int j = 1; j <= m; j++) {
			if (j % 3 == 0) {
				System.out.print(" "+j );
				continue;
			}

			for (int i = j; i > 0; i /= 10) {
				if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				}
			}

		}
		System.out.println();
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		for (int j = 1; j <= m; j++) {
			if (j % 3 == 0) {
				System.out.print(" "+j );
				continue;
			}

			for (int i = j; i > 0; i /= 10) {
				if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				}
			}

		}
		System.out.println();
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		for (int j = 1; j <= m; j++) {
			if (j % 3 == 0) {
				System.out.print(" "+j );
				continue;
			}

			for (int i = j; i > 0; i /= 10) {
				if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				}
			}

		}
		System.out.println();
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		for (int j = 1; j <= m; j++) {
			if (j % 3 == 0) {
				System.out.print(" "+j );
				continue;
			}

			for (int i = j; i > 0; i /= 10) {
				if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				}
			}

		}
		System.out.println();
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc for (int j = 1; j <= m; j++) {
			if (j % 3 == 0) {
				System.out.print(" "+j );
				continue;
			}

			for (int i = j; i > 0; i /= 10) {
				if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				}
			}

		} int j = 1; int j = 1; j 1 j <= m j m j++ j++ j {
			if (j % 3 == 0) {
				System.out.print(" "+j );
				continue;
			}

			for (int i = j; i > 0; i /= 10) {
				if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				}
			}

		} {
			if (j % 3 == 0) {
				System.out.print(" "+j );
				continue;
			}

			for (int i = j; i > 0; i /= 10) {
				if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				}
			}

		} if (j % 3 == 0) {
				System.out.print(" "+j );
				continue;
			} j % 3 == 0 j % 3 j 3 0 {
				System.out.print(" "+j );
				continue;
			} System.out.print(" "+j ) System.out.print System.out System System.out " "+j " " j continue; for (int i = j; i > 0; i /= 10) {
				if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				}
			} int i = j; int i = j; i j i > 0 i 0 i /= 10 i /= 10 i 10 {
				if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				}
			} {
				if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				}
			} if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				} i % 10 == 3 i % 10 i 10 3 {
					System.out.print(" "+j );
					break;
				} System.out.print(" "+j ) System.out.print System.out System System.out " "+j " " j break; System.out.println() System.out.println System.out System System.out sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		for (int j = 1; j <= m; j++) {
			if (j % 3 == 0) {
				System.out.print(" "+j );
				continue;
			}

			for (int i = j; i > 0; i /= 10) {
				if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				}
			}

		}
		System.out.println();
		sc.close();
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		for (int j = 1; j <= m; j++) {
			if (j % 3 == 0) {
				System.out.print(" "+j );
				continue;
			}

			for (int i = j; i > 0; i /= 10) {
				if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				}
			}

		}
		System.out.println();
		sc.close();
	}
} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		for (int j = 1; j <= m; j++) {
			if (j % 3 == 0) {
				System.out.print(" "+j );
				continue;
			}

			for (int i = j; i > 0; i /= 10) {
				if (i % 10 == 3) {
					System.out.print(" "+j );
					break;
				}
			}

		}
		System.out.println();
		sc.close();
	}
}