import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int i = 1;


		while(i <= n){
			int x = i;

			if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				if(x % 10 == 3){
					System.out.print(" " + i);
				}else{
					int y = x;
					while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					}

				}
			}

			i++;
		}
		System.out.println();

	}

} import java.util.Scanner; Scanner java.util public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int i = 1;


		while(i <= n){
			int x = i;

			if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				if(x % 10 == 3){
					System.out.print(" " + i);
				}else{
					int y = x;
					while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					}

				}
			}

			i++;
		}
		System.out.println();

	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int i = 1;


		while(i <= n){
			int x = i;

			if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				if(x % 10 == 3){
					System.out.print(" " + i);
				}else{
					int y = x;
					while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					}

				}
			}

			i++;
		}
		System.out.println();

	} main {
		// TODO 自動生成されたメソッド・スタブ

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int i = 1;


		while(i <= n){
			int x = i;

			if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				if(x % 10 == 3){
					System.out.print(" " + i);
				}else{
					int y = x;
					while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					}

				}
			}

			i++;
		}
		System.out.println();

	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int i = 1; i 1 while(i <= n){
			int x = i;

			if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				if(x % 10 == 3){
					System.out.print(" " + i);
				}else{
					int y = x;
					while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					}

				}
			}

			i++;
		} i <= n i n {
			int x = i;

			if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				if(x % 10 == 3){
					System.out.print(" " + i);
				}else{
					int y = x;
					while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					}

				}
			}

			i++;
		} int x = i; x i if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				if(x % 10 == 3){
					System.out.print(" " + i);
				}else{
					int y = x;
					while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					}

				}
			} x % 3 == 0 x % 3 x 3 0 {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
				if(x % 10 == 3){
					System.out.print(" " + i);
				}else{
					int y = x;
					while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					}

				}
			} if(x % 10 == 3){
					System.out.print(" " + i);
				}else{
					int y = x;
					while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					}

				} x % 10 == 3 x % 10 x 10 3 {
					System.out.print(" " + i);
				} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
					int y = x;
					while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					}

				} int y = x; y x while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					} y > 10 y 10 {
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					} y /= 10 y 10 if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						} y % 10 == 3 y % 10 y 10 3 {
							System.out.print(" " + i);
							break;
						} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i break; i++ i System.out.println() System.out.println System.out System System.out String[] args args public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int i = 1;


		while(i <= n){
			int x = i;

			if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				if(x % 10 == 3){
					System.out.print(" " + i);
				}else{
					int y = x;
					while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					}

				}
			}

			i++;
		}
		System.out.println();

	}

} public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int i = 1;


		while(i <= n){
			int x = i;

			if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				if(x % 10 == 3){
					System.out.print(" " + i);
				}else{
					int y = x;
					while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					}

				}
			}

			i++;
		}
		System.out.println();

	}

} Main
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int i = 1;


		while(i <= n){
			int x = i;

			if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				if(x % 10 == 3){
					System.out.print(" " + i);
				}else{
					int y = x;
					while(y > 10){
						y /= 10;
						if(y % 10 == 3){
							System.out.print(" " + i);
							break;
						}
					}

				}
			}

			i++;
		}
		System.out.println();

	}

}
