import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		long i = 1;
		long x = i;
		boolean checkFlg = true;
		while (true) {
			if (checkFlg) {
				x = i;
			}
			if (x % 3 == 0 & checkFlg) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}
			
			if (x % 10 == 3) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}

			x /= 10;
			if (x != 0) {
				checkFlg = false;
				continue;
			}

			if (++i <= n) {
				checkFlg = true;
				continue;
			} else {
				break;
			}
		}
		System.out.println("");
	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		long i = 1;
		long x = i;
		boolean checkFlg = true;
		while (true) {
			if (checkFlg) {
				x = i;
			}
			if (x % 3 == 0 & checkFlg) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}
			
			if (x % 10 == 3) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}

			x /= 10;
			if (x != 0) {
				checkFlg = false;
				continue;
			}

			if (++i <= n) {
				checkFlg = true;
				continue;
			} else {
				break;
			}
		}
		System.out.println("");
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		long i = 1;
		long x = i;
		boolean checkFlg = true;
		while (true) {
			if (checkFlg) {
				x = i;
			}
			if (x % 3 == 0 & checkFlg) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}
			
			if (x % 10 == 3) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}

			x /= 10;
			if (x != 0) {
				checkFlg = false;
				continue;
			}

			if (++i <= n) {
				checkFlg = true;
				continue;
			} else {
				break;
			}
		}
		System.out.println("");
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		long i = 1;
		long x = i;
		boolean checkFlg = true;
		while (true) {
			if (checkFlg) {
				x = i;
			}
			if (x % 3 == 0 & checkFlg) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}
			
			if (x % 10 == 3) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}

			x /= 10;
			if (x != 0) {
				checkFlg = false;
				continue;
			}

			if (++i <= n) {
				checkFlg = true;
				continue;
			} else {
				break;
			}
		}
		System.out.println("");
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) long n = Long.parseLong(br.readLine()); n Long.parseLong(br.readLine()) Long.parseLong Long br.readLine() br.readLine br long i = 1; i 1 long x = i; x i boolean checkFlg = true; checkFlg true while (true) {
			if (checkFlg) {
				x = i;
			}
			if (x % 3 == 0 & checkFlg) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}
			
			if (x % 10 == 3) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}

			x /= 10;
			if (x != 0) {
				checkFlg = false;
				continue;
			}

			if (++i <= n) {
				checkFlg = true;
				continue;
			} else {
				break;
			}
		} true {
			if (checkFlg) {
				x = i;
			}
			if (x % 3 == 0 & checkFlg) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}
			
			if (x % 10 == 3) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}

			x /= 10;
			if (x != 0) {
				checkFlg = false;
				continue;
			}

			if (++i <= n) {
				checkFlg = true;
				continue;
			} else {
				break;
			}
		} if (checkFlg) {
				x = i;
			} checkFlg {
				x = i;
			} x = i x i if (x % 3 == 0 & checkFlg) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			} x % 3 == 0 & checkFlg x % 3 == 0 x % 3 x 3 0 checkFlg {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				} ++i <= n ++i i n {
					checkFlg = true;
					continue;
				} checkFlg = true checkFlg true continue; {
					break;
				} break; if (x % 10 == 3) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			} x % 10 == 3 x % 10 x 10 3 {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				} ++i <= n ++i i n {
					checkFlg = true;
					continue;
				} checkFlg = true checkFlg true continue; {
					break;
				} break; x /= 10 x 10 if (x != 0) {
				checkFlg = false;
				continue;
			} x != 0 x 0 {
				checkFlg = false;
				continue;
			} checkFlg = false checkFlg false continue; if (++i <= n) {
				checkFlg = true;
				continue;
			} else {
				break;
			} ++i <= n ++i i n {
				checkFlg = true;
				continue;
			} checkFlg = true checkFlg true continue; {
				break;
			} break; System.out.println("") System.out.println System.out System System.out "" String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		long i = 1;
		long x = i;
		boolean checkFlg = true;
		while (true) {
			if (checkFlg) {
				x = i;
			}
			if (x % 3 == 0 & checkFlg) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}
			
			if (x % 10 == 3) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}

			x /= 10;
			if (x != 0) {
				checkFlg = false;
				continue;
			}

			if (++i <= n) {
				checkFlg = true;
				continue;
			} else {
				break;
			}
		}
		System.out.println("");
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		long i = 1;
		long x = i;
		boolean checkFlg = true;
		while (true) {
			if (checkFlg) {
				x = i;
			}
			if (x % 3 == 0 & checkFlg) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}
			
			if (x % 10 == 3) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}

			x /= 10;
			if (x != 0) {
				checkFlg = false;
				continue;
			}

			if (++i <= n) {
				checkFlg = true;
				continue;
			} else {
				break;
			}
		}
		System.out.println("");
	}
} Main
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		long i = 1;
		long x = i;
		boolean checkFlg = true;
		while (true) {
			if (checkFlg) {
				x = i;
			}
			if (x % 3 == 0 & checkFlg) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}
			
			if (x % 10 == 3) {
				System.out.print(" " + i);
				if (++i <= n) {
					checkFlg = true;
					continue;
				} else {
					break;
				}
			}

			x /= 10;
			if (x != 0) {
				checkFlg = false;
				continue;
			}

			if (++i <= n) {
				checkFlg = true;
				continue;
			} else {
				break;
			}
		}
		System.out.println("");
	}
}