import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String s = reader.readLine();
				
			int n = Integer.parseInt(s);
			
			int i = 1;
			while (++ i <= n) {
				int x = i;
				if (x % 3 == 0) {
					System.out.print(" ");
					System.out.print(i);
					continue;
				}
				do {
					if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					}
					x /= 10;
				} while (x != 0);
			}
			System.out.println();				
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String s = reader.readLine();
				
			int n = Integer.parseInt(s);
			
			int i = 1;
			while (++ i <= n) {
				int x = i;
				if (x % 3 == 0) {
					System.out.print(" ");
					System.out.print(i);
					continue;
				}
				do {
					if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					}
					x /= 10;
				} while (x != 0);
			}
			System.out.println();				
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

} Main public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String s = reader.readLine();
				
			int n = Integer.parseInt(s);
			
			int i = 1;
			while (++ i <= n) {
				int x = i;
				if (x % 3 == 0) {
					System.out.print(" ");
					System.out.print(i);
					continue;
				}
				do {
					if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					}
					x /= 10;
				} while (x != 0);
			}
			System.out.println();				
		} catch (IOException e) {
			e.printStackTrace();
		}
	} main {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String s = reader.readLine();
				
			int n = Integer.parseInt(s);
			
			int i = 1;
			while (++ i <= n) {
				int x = i;
				if (x % 3 == 0) {
					System.out.print(" ");
					System.out.print(i);
					continue;
				}
				do {
					if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					}
					x /= 10;
				} while (x != 0);
			}
			System.out.println();				
		} catch (IOException e) {
			e.printStackTrace();
		}
	} try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String s = reader.readLine();
				
			int n = Integer.parseInt(s);
			
			int i = 1;
			while (++ i <= n) {
				int x = i;
				if (x % 3 == 0) {
					System.out.print(" ");
					System.out.print(i);
					continue;
				}
				do {
					if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					}
					x /= 10;
				} while (x != 0);
			}
			System.out.println();				
		} catch (IOException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String s = reader.readLine();
				
			int n = Integer.parseInt(s);
			
			int i = 1;
			while (++ i <= n) {
				int x = i;
				if (x % 3 == 0) {
					System.out.print(" ");
					System.out.print(i);
					continue;
				}
				do {
					if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					}
					x /= 10;
				} while (x != 0);
			}
			System.out.println();				
		} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) String s = reader.readLine(); s reader.readLine() reader.readLine reader int n = Integer.parseInt(s); n Integer.parseInt(s) Integer.parseInt Integer s int i = 1; i 1 while (++ i <= n) {
				int x = i;
				if (x % 3 == 0) {
					System.out.print(" ");
					System.out.print(i);
					continue;
				}
				do {
					if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					}
					x /= 10;
				} while (x != 0);
			} ++ i <= n ++ i i n {
				int x = i;
				if (x % 3 == 0) {
					System.out.print(" ");
					System.out.print(i);
					continue;
				}
				do {
					if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					}
					x /= 10;
				} while (x != 0);
			} int x = i; x i if (x % 3 == 0) {
					System.out.print(" ");
					System.out.print(i);
					continue;
				} x % 3 == 0 x % 3 x 3 0 {
					System.out.print(" ");
					System.out.print(i);
					continue;
				} System.out.print(" ") System.out.print System.out System System.out " " System.out.print(i) System.out.print System.out System System.out i continue; do {
					if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					}
					x /= 10;
				} while (x != 0); x != 0 x 0 {
					if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					}
					x /= 10;
				} if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					} x % 10 == 3 x % 10 x 10 3 {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					} System.out.print(" ") System.out.print System.out System System.out " " System.out.print(i) System.out.print System.out System System.out i break; x /= 10 x 10 System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String s = reader.readLine();
				
			int n = Integer.parseInt(s);
			
			int i = 1;
			while (++ i <= n) {
				int x = i;
				if (x % 3 == 0) {
					System.out.print(" ");
					System.out.print(i);
					continue;
				}
				do {
					if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					}
					x /= 10;
				} while (x != 0);
			}
			System.out.println();				
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

} public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String s = reader.readLine();
				
			int n = Integer.parseInt(s);
			
			int i = 1;
			while (++ i <= n) {
				int x = i;
				if (x % 3 == 0) {
					System.out.print(" ");
					System.out.print(i);
					continue;
				}
				do {
					if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					}
					x /= 10;
				} while (x != 0);
			}
			System.out.println();				
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String s = reader.readLine();
				
			int n = Integer.parseInt(s);
			
			int i = 1;
			while (++ i <= n) {
				int x = i;
				if (x % 3 == 0) {
					System.out.print(" ");
					System.out.print(i);
					continue;
				}
				do {
					if (x % 10 == 3) {
						System.out.print(" ");
				 		System.out.print(i);
						break;
					}
					x /= 10;
				} while (x != 0);
			}
			System.out.println();				
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}