
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 1;
		int y;
		do {
			if (x % 3 == 0 || x % 10 == 3) {
				System.out.printf(" %d", x);
			} else if (x >= 30) {
				y = x;
				while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				}
			}
		} while (++x <= n);
		System.out.println();
	}

} 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();
		int x = 1;
		int y;
		do {
			if (x % 3 == 0 || x % 10 == 3) {
				System.out.printf(" %d", x);
			} else if (x >= 30) {
				y = x;
				while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				}
			}
		} while (++x <= n);
		System.out.println();
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 1;
		int y;
		do {
			if (x % 3 == 0 || x % 10 == 3) {
				System.out.printf(" %d", x);
			} else if (x >= 30) {
				y = x;
				while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				}
			}
		} while (++x <= n);
		System.out.println();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 1;
		int y;
		do {
			if (x % 3 == 0 || x % 10 == 3) {
				System.out.printf(" %d", x);
			} else if (x >= 30) {
				y = x;
				while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				}
			}
		} while (++x <= n);
		System.out.println();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x = 1; x 1 int y; y do {
			if (x % 3 == 0 || x % 10 == 3) {
				System.out.printf(" %d", x);
			} else if (x >= 30) {
				y = x;
				while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				}
			}
		} while (++x <= n); ++x <= n ++x x n {
			if (x % 3 == 0 || x % 10 == 3) {
				System.out.printf(" %d", x);
			} else if (x >= 30) {
				y = x;
				while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				}
			}
		} if (x % 3 == 0 || x % 10 == 3) {
				System.out.printf(" %d", x);
			} else if (x >= 30) {
				y = x;
				while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				}
			} x % 3 == 0 || x % 10 == 3 x % 3 == 0 x % 3 x 3 0 x % 10 == 3 x % 10 x 10 3 {
				System.out.printf(" %d", x);
			} System.out.printf(" %d", x) System.out.printf System.out System System.out " %d" x if (x >= 30) {
				y = x;
				while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				}
			} x >= 30 x 30 {
				y = x;
				while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				}
			} y = x y x while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				} y >= 30 y 30 {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				} y = y / 10 y y / 10 y 10 if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					} y == 3 || y % 10 == 3 y == 3 y 3 y % 10 == 3 y % 10 y 10 3 {
						System.out.printf(" %d", x);
						break;
					} System.out.printf(" %d", x) System.out.printf System.out System System.out " %d" x break; System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 1;
		int y;
		do {
			if (x % 3 == 0 || x % 10 == 3) {
				System.out.printf(" %d", x);
			} else if (x >= 30) {
				y = x;
				while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				}
			}
		} while (++x <= n);
		System.out.println();
	}

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 1;
		int y;
		do {
			if (x % 3 == 0 || x % 10 == 3) {
				System.out.printf(" %d", x);
			} else if (x >= 30) {
				y = x;
				while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				}
			}
		} while (++x <= n);
		System.out.println();
	}

} Main

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 1;
		int y;
		do {
			if (x % 3 == 0 || x % 10 == 3) {
				System.out.printf(" %d", x);
			} else if (x >= 30) {
				y = x;
				while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				}
			}
		} while (++x <= n);
		System.out.println();
	}

}