import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		int x = i;
		int start = 0;

		while (i <= n) {
			if (start == 0) {
				x = i;
				if (x % 3 == 0) {
					System.out.print(" " + i);
					start = 2;
				}
			}
			if (start <= 1) {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					start = 2;
				}
				if (start <= 1) {
					x /= 10;
					if (0 < x) {
						start = 1;
						continue;
					}
				}
			}
			i++;
			start = 0;
		}

		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 i = 1;
		int x = i;
		int start = 0;

		while (i <= n) {
			if (start == 0) {
				x = i;
				if (x % 3 == 0) {
					System.out.print(" " + i);
					start = 2;
				}
			}
			if (start <= 1) {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					start = 2;
				}
				if (start <= 1) {
					x /= 10;
					if (0 < x) {
						start = 1;
						continue;
					}
				}
			}
			i++;
			start = 0;
		}

		System.out.println();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		int x = i;
		int start = 0;

		while (i <= n) {
			if (start == 0) {
				x = i;
				if (x % 3 == 0) {
					System.out.print(" " + i);
					start = 2;
				}
			}
			if (start <= 1) {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					start = 2;
				}
				if (start <= 1) {
					x /= 10;
					if (0 < x) {
						start = 1;
						continue;
					}
				}
			}
			i++;
			start = 0;
		}

		System.out.println();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		int x = i;
		int start = 0;

		while (i <= n) {
			if (start == 0) {
				x = i;
				if (x % 3 == 0) {
					System.out.print(" " + i);
					start = 2;
				}
			}
			if (start <= 1) {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					start = 2;
				}
				if (start <= 1) {
					x /= 10;
					if (0 < x) {
						start = 1;
						continue;
					}
				}
			}
			i++;
			start = 0;
		}

		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 i = 1; i 1 int x = i; x i int start = 0; start 0 while (i <= n) {
			if (start == 0) {
				x = i;
				if (x % 3 == 0) {
					System.out.print(" " + i);
					start = 2;
				}
			}
			if (start <= 1) {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					start = 2;
				}
				if (start <= 1) {
					x /= 10;
					if (0 < x) {
						start = 1;
						continue;
					}
				}
			}
			i++;
			start = 0;
		} i <= n i n {
			if (start == 0) {
				x = i;
				if (x % 3 == 0) {
					System.out.print(" " + i);
					start = 2;
				}
			}
			if (start <= 1) {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					start = 2;
				}
				if (start <= 1) {
					x /= 10;
					if (0 < x) {
						start = 1;
						continue;
					}
				}
			}
			i++;
			start = 0;
		} if (start == 0) {
				x = i;
				if (x % 3 == 0) {
					System.out.print(" " + i);
					start = 2;
				}
			} start == 0 start 0 {
				x = i;
				if (x % 3 == 0) {
					System.out.print(" " + i);
					start = 2;
				}
			} x = i x i if (x % 3 == 0) {
					System.out.print(" " + i);
					start = 2;
				} x % 3 == 0 x % 3 x 3 0 {
					System.out.print(" " + i);
					start = 2;
				} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i start = 2 start 2 if (start <= 1) {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					start = 2;
				}
				if (start <= 1) {
					x /= 10;
					if (0 < x) {
						start = 1;
						continue;
					}
				}
			} start <= 1 start 1 {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					start = 2;
				}
				if (start <= 1) {
					x /= 10;
					if (0 < x) {
						start = 1;
						continue;
					}
				}
			} if (x % 10 == 3) {
					System.out.print(" " + i);
					start = 2;
				} x % 10 == 3 x % 10 x 10 3 {
					System.out.print(" " + i);
					start = 2;
				} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i start = 2 start 2 if (start <= 1) {
					x /= 10;
					if (0 < x) {
						start = 1;
						continue;
					}
				} start <= 1 start 1 {
					x /= 10;
					if (0 < x) {
						start = 1;
						continue;
					}
				} x /= 10 x 10 if (0 < x) {
						start = 1;
						continue;
					} 0 < x 0 x {
						start = 1;
						continue;
					} start = 1 start 1 continue; i++ i start = 0 start 0 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 i = 1;
		int x = i;
		int start = 0;

		while (i <= n) {
			if (start == 0) {
				x = i;
				if (x % 3 == 0) {
					System.out.print(" " + i);
					start = 2;
				}
			}
			if (start <= 1) {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					start = 2;
				}
				if (start <= 1) {
					x /= 10;
					if (0 < x) {
						start = 1;
						continue;
					}
				}
			}
			i++;
			start = 0;
		}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		int x = i;
		int start = 0;

		while (i <= n) {
			if (start == 0) {
				x = i;
				if (x % 3 == 0) {
					System.out.print(" " + i);
					start = 2;
				}
			}
			if (start <= 1) {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					start = 2;
				}
				if (start <= 1) {
					x /= 10;
					if (0 < x) {
						start = 1;
						continue;
					}
				}
			}
			i++;
			start = 0;
		}

		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 i = 1;
		int x = i;
		int start = 0;

		while (i <= n) {
			if (start == 0) {
				x = i;
				if (x % 3 == 0) {
					System.out.print(" " + i);
					start = 2;
				}
			}
			if (start <= 1) {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					start = 2;
				}
				if (start <= 1) {
					x /= 10;
					if (0 < x) {
						start = 1;
						continue;
					}
				}
			}
			i++;
			start = 0;
		}

		System.out.println();
	}
}