import java.util.Scanner;

public class Main {
	static Scanner scan = new Scanner(System.in);	
	public static void main(String[] args) {
		int n = Integer.parseInt(scan.next());
		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0) {
				System.out.print(" " + i);
			} else {
			int a = i;
				while(true) {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				}
			}
		}
		System.out.println();

	}
} import java.util.Scanner; Scanner java.util public class Main {
	static Scanner scan = new Scanner(System.in);	
	public static void main(String[] args) {
		int n = Integer.parseInt(scan.next());
		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0) {
				System.out.print(" " + i);
			} else {
			int a = i;
				while(true) {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				}
			}
		}
		System.out.println();

	}
} Main static Scanner scan = new Scanner(System.in); scan new Scanner(System.in) public static void main(String[] args) {
		int n = Integer.parseInt(scan.next());
		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0) {
				System.out.print(" " + i);
			} else {
			int a = i;
				while(true) {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				}
			}
		}
		System.out.println();

	} main {
		int n = Integer.parseInt(scan.next());
		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0) {
				System.out.print(" " + i);
			} else {
			int a = i;
				while(true) {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				}
			}
		}
		System.out.println();

	} int n = Integer.parseInt(scan.next()); n Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan for(int i = 1; i <= n; i++) {
			if(i % 3 == 0) {
				System.out.print(" " + i);
			} else {
			int a = i;
				while(true) {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				}
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if(i % 3 == 0) {
				System.out.print(" " + i);
			} else {
			int a = i;
				while(true) {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				}
			}
		} {
			if(i % 3 == 0) {
				System.out.print(" " + i);
			} else {
			int a = i;
				while(true) {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				}
			}
		} if(i % 3 == 0) {
				System.out.print(" " + i);
			} else {
			int a = i;
				while(true) {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				}
			} i % 3 == 0 i % 3 i 3 0 {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
			int a = i;
				while(true) {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				}
			} int a = i; a i while(true) {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				} true {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				} if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					} a % 10 == 3 a % 10 a 10 3 {
						System.out.print(" " + i);
						break;
					} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i break; a = a / 10 a a / 10 a 10 if(a == 0) {
						break;
					} a == 0 a 0 {
						break;
					} break; System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	static Scanner scan = new Scanner(System.in);	
	public static void main(String[] args) {
		int n = Integer.parseInt(scan.next());
		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0) {
				System.out.print(" " + i);
			} else {
			int a = i;
				while(true) {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				}
			}
		}
		System.out.println();

	}
} public class Main {
	static Scanner scan = new Scanner(System.in);	
	public static void main(String[] args) {
		int n = Integer.parseInt(scan.next());
		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0) {
				System.out.print(" " + i);
			} else {
			int a = i;
				while(true) {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				}
			}
		}
		System.out.println();

	}
} Main
import java.util.Scanner;

public class Main {
	static Scanner scan = new Scanner(System.in);	
	public static void main(String[] args) {
		int n = Integer.parseInt(scan.next());
		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0) {
				System.out.print(" " + i);
			} else {
			int a = i;
				while(true) {
					if(a % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					a = a / 10;
					if(a == 0) {
						break;
					}
				}
			}
		}
		System.out.println();

	}
}