import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + x);
			} else {
				String value = String.valueOf(x);
				for (int index = value.length(); index > 0; index--) {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						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 n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + x);
			} else {
				String value = String.valueOf(x);
				for (int index = value.length(); index > 0; index--) {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					}
				}
			}
		}
		System.out.println();
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + x);
			} else {
				String value = String.valueOf(x);
				for (int index = value.length(); index > 0; index--) {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					}
				}
			}
		}
		System.out.println();
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + x);
			} else {
				String value = String.valueOf(x);
				for (int index = value.length(); index > 0; index--) {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					}
				}
			}
		}
		System.out.println();
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + x);
			} else {
				String value = String.valueOf(x);
				for (int index = value.length(); index > 0; index--) {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					}
				}
			}
		} 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(" " + x);
			} else {
				String value = String.valueOf(x);
				for (int index = value.length(); index > 0; index--) {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					}
				}
			}
		} {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + x);
			} else {
				String value = String.valueOf(x);
				for (int index = value.length(); index > 0; index--) {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					}
				}
			}
		} int x = i; x i if (x % 3 == 0) {
				System.out.print(" " + x);
			} else {
				String value = String.valueOf(x);
				for (int index = value.length(); index > 0; index--) {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					}
				}
			} x % 3 == 0 x % 3 x 3 0 {
				System.out.print(" " + x);
			} System.out.print(" " + x) System.out.print System.out System System.out " " + x " " x {
				String value = String.valueOf(x);
				for (int index = value.length(); index > 0; index--) {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					}
				}
			} String value = String.valueOf(x); value String.valueOf(x) String.valueOf String x for (int index = value.length(); index > 0; index--) {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					}
				} int index = value.length(); int index = value.length(); index value.length() value.length value index > 0 index 0 index-- index-- index {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					}
				} {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					}
				} if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					} x / (int) Math.pow(10, index - 1) % 10 == 3 x / (int) Math.pow(10, index - 1) % 10 x / (int) Math.pow(10, index - 1) x (int) Math.pow(10, index - 1) Math.pow Math 10 index - 1 index 1 10 3 {
						System.out.print(" " + x);
						break;
					} System.out.print(" " + x) System.out.print System.out System System.out " " + x " " x 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 n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + x);
			} else {
				String value = String.valueOf(x);
				for (int index = value.length(); index > 0; index--) {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					}
				}
			}
		}
		System.out.println();
		sc.close();
	}
} public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + x);
			} else {
				String value = String.valueOf(x);
				for (int index = value.length(); index > 0; index--) {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						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 n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + x);
			} else {
				String value = String.valueOf(x);
				for (int index = value.length(); index > 0; index--) {
					if (x / (int) Math.pow(10, index - 1) % 10 == 3) {
						System.out.print(" " + x);
						break;
					}
				}
			}
		}
		System.out.println();
		sc.close();
	}
}
