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

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			x = in.readLine();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		int n = Integer.parseInt(x);
		
		for (int i = 0; i < n; i++) {
			int num = i + 1;
			if (((num % 3) == 0) || ((num % 10) == 3)) {
				System.out.print(" " + (i + 1));
			} else {
				while (num != 0) {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				}
			}
		}
		System.out.println();
	}
} 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) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			x = in.readLine();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		int n = Integer.parseInt(x);
		
		for (int i = 0; i < n; i++) {
			int num = i + 1;
			if (((num % 3) == 0) || ((num % 10) == 3)) {
				System.out.print(" " + (i + 1));
			} else {
				while (num != 0) {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				}
			}
		}
		System.out.println();
	}
} Main public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			x = in.readLine();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		int n = Integer.parseInt(x);
		
		for (int i = 0; i < n; i++) {
			int num = i + 1;
			if (((num % 3) == 0) || ((num % 10) == 3)) {
				System.out.print(" " + (i + 1));
			} else {
				while (num != 0) {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				}
			}
		}
		System.out.println();
	} main {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			x = in.readLine();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		int n = Integer.parseInt(x);
		
		for (int i = 0; i < n; i++) {
			int num = i + 1;
			if (((num % 3) == 0) || ((num % 10) == 3)) {
				System.out.print(" " + (i + 1));
			} else {
				while (num != 0) {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				}
			}
		}
		System.out.println();
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) String x = ""; x "" try {
			x = in.readLine();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} NumberFormatException e {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} IOException e {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			x = in.readLine();
		} x = in.readLine() x in.readLine() in.readLine in int n = Integer.parseInt(x); n Integer.parseInt(x) Integer.parseInt Integer x for (int i = 0; i < n; i++) {
			int num = i + 1;
			if (((num % 3) == 0) || ((num % 10) == 3)) {
				System.out.print(" " + (i + 1));
			} else {
				while (num != 0) {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int num = i + 1;
			if (((num % 3) == 0) || ((num % 10) == 3)) {
				System.out.print(" " + (i + 1));
			} else {
				while (num != 0) {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				}
			}
		} {
			int num = i + 1;
			if (((num % 3) == 0) || ((num % 10) == 3)) {
				System.out.print(" " + (i + 1));
			} else {
				while (num != 0) {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				}
			}
		} int num = i + 1; num i + 1 i 1 if (((num % 3) == 0) || ((num % 10) == 3)) {
				System.out.print(" " + (i + 1));
			} else {
				while (num != 0) {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				}
			} ((num % 3) == 0) || ((num % 10) == 3) ((num % 3) == 0) (num % 3) num 3 0 ((num % 10) == 3) (num % 10) num 10 3 {
				System.out.print(" " + (i + 1));
			} System.out.print(" " + (i + 1)) System.out.print System.out System System.out " " + (i + 1) " " (i + 1) i 1 {
				while (num != 0) {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				}
			} while (num != 0) {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				} num != 0 num 0 {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				} num = num / 10 num num / 10 num 10 if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					} (num % 10) == 3 (num % 10) num 10 3 {
						System.out.print(" " + (i + 1));
						break;
					} System.out.print(" " + (i + 1)) System.out.print System.out System System.out " " + (i + 1) " " (i + 1) i 1 break; System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			x = in.readLine();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		int n = Integer.parseInt(x);
		
		for (int i = 0; i < n; i++) {
			int num = i + 1;
			if (((num % 3) == 0) || ((num % 10) == 3)) {
				System.out.print(" " + (i + 1));
			} else {
				while (num != 0) {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				}
			}
		}
		System.out.println();
	}
} public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			x = in.readLine();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		int n = Integer.parseInt(x);
		
		for (int i = 0; i < n; i++) {
			int num = i + 1;
			if (((num % 3) == 0) || ((num % 10) == 3)) {
				System.out.print(" " + (i + 1));
			} else {
				while (num != 0) {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				}
			}
		}
		System.out.println();
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			x = in.readLine();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		int n = Integer.parseInt(x);
		
		for (int i = 0; i < n; i++) {
			int num = i + 1;
			if (((num % 3) == 0) || ((num % 10) == 3)) {
				System.out.print(" " + (i + 1));
			} else {
				while (num != 0) {
					num = num / 10;
					if ((num % 10) == 3) {
						System.out.print(" " + (i + 1));
						break;
					}
				}
			}
		}
		System.out.println();
	}
}