import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();

		for(int i = 1;i <= count;i++ ) {
			int num = 0;
			if(i % 3 == 0) {
				num = i;
			} else if(i % 10 == 3) {
				num = i;
			} else if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			}

			if(num != 0) {
				System.out.print(" " + num);
			}

		}
		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 count = sc.nextInt();

		for(int i = 1;i <= count;i++ ) {
			int num = 0;
			if(i % 3 == 0) {
				num = i;
			} else if(i % 10 == 3) {
				num = i;
			} else if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			}

			if(num != 0) {
				System.out.print(" " + num);
			}

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

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();

		for(int i = 1;i <= count;i++ ) {
			int num = 0;
			if(i % 3 == 0) {
				num = i;
			} else if(i % 10 == 3) {
				num = i;
			} else if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			}

			if(num != 0) {
				System.out.print(" " + num);
			}

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

	} main {
		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();

		for(int i = 1;i <= count;i++ ) {
			int num = 0;
			if(i % 3 == 0) {
				num = i;
			} else if(i % 10 == 3) {
				num = i;
			} else if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			}

			if(num != 0) {
				System.out.print(" " + num);
			}

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

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int count = sc.nextInt(); count sc.nextInt() sc.nextInt sc for(int i = 1;i <= count;i++ ) {
			int num = 0;
			if(i % 3 == 0) {
				num = i;
			} else if(i % 10 == 3) {
				num = i;
			} else if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			}

			if(num != 0) {
				System.out.print(" " + num);
			}

		} int i = 1; int i = 1; i 1 i <= count i count i++ i++ i {
			int num = 0;
			if(i % 3 == 0) {
				num = i;
			} else if(i % 10 == 3) {
				num = i;
			} else if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			}

			if(num != 0) {
				System.out.print(" " + num);
			}

		} {
			int num = 0;
			if(i % 3 == 0) {
				num = i;
			} else if(i % 10 == 3) {
				num = i;
			} else if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			}

			if(num != 0) {
				System.out.print(" " + num);
			}

		} int num = 0; num 0 if(i % 3 == 0) {
				num = i;
			} else if(i % 10 == 3) {
				num = i;
			} else if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			} i % 3 == 0 i % 3 i 3 0 {
				num = i;
			} num = i num i if(i % 10 == 3) {
				num = i;
			} else if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			} i % 10 == 3 i % 10 i 10 3 {
				num = i;
			} num = i num i if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			} (i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3 (i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3 (i / 10) %  10 == 3 (i / 10) %  10 (i / 10) i 10 10 3 (i / 100) %  10 == 3 (i / 100) %  10 (i / 100) i 100 10 3 (i / 1000) %  10 == 3 (i / 1000) %  10 (i / 1000) i 1000 10 3 {
				num = i;
			} num = i num i if(num != 0) {
				System.out.print(" " + num);
			} num != 0 num 0 {
				System.out.print(" " + num);
			} System.out.print(" " + num) System.out.print System.out System System.out " " + num " " num 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 count = sc.nextInt();

		for(int i = 1;i <= count;i++ ) {
			int num = 0;
			if(i % 3 == 0) {
				num = i;
			} else if(i % 10 == 3) {
				num = i;
			} else if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			}

			if(num != 0) {
				System.out.print(" " + num);
			}

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

	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();

		for(int i = 1;i <= count;i++ ) {
			int num = 0;
			if(i % 3 == 0) {
				num = i;
			} else if(i % 10 == 3) {
				num = i;
			} else if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			}

			if(num != 0) {
				System.out.print(" " + num);
			}

		}
		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 count = sc.nextInt();

		for(int i = 1;i <= count;i++ ) {
			int num = 0;
			if(i % 3 == 0) {
				num = i;
			} else if(i % 10 == 3) {
				num = i;
			} else if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			}

			if(num != 0) {
				System.out.print(" " + num);
			}

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

	}
}