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 swi;

		while (i <= n) {
			int x = i;
			swi = 0;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				swi = 1;
			}
			while (x != 0) {
				if (swi == 0) {
					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					}
				}
				x = x / 10;
			}
			i++;

		}
		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();
		int i = 1;
		int swi;

		while (i <= n) {
			int x = i;
			swi = 0;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				swi = 1;
			}
			while (x != 0) {
				if (swi == 0) {
					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					}
				}
				x = x / 10;
			}
			i++;

		}
		System.out.println();
		sc.close();
	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		int swi;

		while (i <= n) {
			int x = i;
			swi = 0;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				swi = 1;
			}
			while (x != 0) {
				if (swi == 0) {
					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					}
				}
				x = x / 10;
			}
			i++;

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

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		int swi;

		while (i <= n) {
			int x = i;
			swi = 0;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				swi = 1;
			}
			while (x != 0) {
				if (swi == 0) {
					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					}
				}
				x = x / 10;
			}
			i++;

		}
		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 int i = 1; i 1 int swi; swi while (i <= n) {
			int x = i;
			swi = 0;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				swi = 1;
			}
			while (x != 0) {
				if (swi == 0) {
					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					}
				}
				x = x / 10;
			}
			i++;

		} i <= n i n {
			int x = i;
			swi = 0;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				swi = 1;
			}
			while (x != 0) {
				if (swi == 0) {
					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					}
				}
				x = x / 10;
			}
			i++;

		} int x = i; x i swi = 0 swi 0 if (x % 3 == 0) {
				System.out.printf(" %d", i);
				swi = 1;
			} x % 3 == 0 x % 3 x 3 0 {
				System.out.printf(" %d", i);
				swi = 1;
			} System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i swi = 1 swi 1 while (x != 0) {
				if (swi == 0) {
					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					}
				}
				x = x / 10;
			} x != 0 x 0 {
				if (swi == 0) {
					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					}
				}
				x = x / 10;
			} if (swi == 0) {
					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					}
				} swi == 0 swi 0 {
					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					}
				} if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					} x % 10 == 3 x % 10 x 10 3 {
						System.out.printf(" %d", i);
						swi = 1;
					} System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i swi = 1 swi 1 x = x / 10 x x / 10 x 10 i++ i 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();
		int i = 1;
		int swi;

		while (i <= n) {
			int x = i;
			swi = 0;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				swi = 1;
			}
			while (x != 0) {
				if (swi == 0) {
					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					}
				}
				x = x / 10;
			}
			i++;

		}
		System.out.println();
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		int swi;

		while (i <= n) {
			int x = i;
			swi = 0;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				swi = 1;
			}
			while (x != 0) {
				if (swi == 0) {
					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					}
				}
				x = x / 10;
			}
			i++;

		}
		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();
		int i = 1;
		int swi;

		while (i <= n) {
			int x = i;
			swi = 0;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				swi = 1;
			}
			while (x != 0) {
				if (swi == 0) {
					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						swi = 1;
					}
				}
				x = x / 10;
			}
			i++;

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