import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner stdin = new Scanner(System.in)) {
			int n = Integer.parseInt(stdin.next());
			if (n < 3 || n > 10000) {
				throw new RuntimeException("Input Range:between 3 and 10000");
			}
			System.out.println(checkNum(n));

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static String checkNum(int n) {
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(' ').append(String.valueOf(i));
			} else if (String.valueOf(i).contains("3")) {
				sb.append(' ').append(String.valueOf(i));
			}
		}
		return sb.toString();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		try (Scanner stdin = new Scanner(System.in)) {
			int n = Integer.parseInt(stdin.next());
			if (n < 3 || n > 10000) {
				throw new RuntimeException("Input Range:between 3 and 10000");
			}
			System.out.println(checkNum(n));

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static String checkNum(int n) {
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(' ').append(String.valueOf(i));
			} else if (String.valueOf(i).contains("3")) {
				sb.append(' ').append(String.valueOf(i));
			}
		}
		return sb.toString();
	}
} Main public static void main(String[] args) {
		try (Scanner stdin = new Scanner(System.in)) {
			int n = Integer.parseInt(stdin.next());
			if (n < 3 || n > 10000) {
				throw new RuntimeException("Input Range:between 3 and 10000");
			}
			System.out.println(checkNum(n));

		} catch (Exception e) {
			e.printStackTrace();
		}
	} main {
		try (Scanner stdin = new Scanner(System.in)) {
			int n = Integer.parseInt(stdin.next());
			if (n < 3 || n > 10000) {
				throw new RuntimeException("Input Range:between 3 and 10000");
			}
			System.out.println(checkNum(n));

		} catch (Exception e) {
			e.printStackTrace();
		}
	} try (Scanner stdin = new Scanner(System.in)) {
			int n = Integer.parseInt(stdin.next());
			if (n < 3 || n > 10000) {
				throw new RuntimeException("Input Range:between 3 and 10000");
			}
			System.out.println(checkNum(n));

		} catch (Exception e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} Exception e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			int n = Integer.parseInt(stdin.next());
			if (n < 3 || n > 10000) {
				throw new RuntimeException("Input Range:between 3 and 10000");
			}
			System.out.println(checkNum(n));

		} Scanner stdin = new Scanner(System.in) Scanner stdin = new Scanner(System.in) new Scanner(System.in) int n = Integer.parseInt(stdin.next()); n Integer.parseInt(stdin.next()) Integer.parseInt Integer stdin.next() stdin.next stdin if (n < 3 || n > 10000) {
				throw new RuntimeException("Input Range:between 3 and 10000");
			} n < 3 || n > 10000 n < 3 n 3 n > 10000 n 10000 {
				throw new RuntimeException("Input Range:between 3 and 10000");
			} throw new RuntimeException("Input Range:between 3 and 10000"); new RuntimeException("Input Range:between 3 and 10000") System.out.println(checkNum(n)) System.out.println System.out System System.out checkNum(n) checkNum n String[] args args private static String checkNum(int n) {
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(' ').append(String.valueOf(i));
			} else if (String.valueOf(i).contains("3")) {
				sb.append(' ').append(String.valueOf(i));
			}
		}
		return sb.toString();
	} checkNum {
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(' ').append(String.valueOf(i));
			} else if (String.valueOf(i).contains("3")) {
				sb.append(' ').append(String.valueOf(i));
			}
		}
		return sb.toString();
	} StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(' ').append(String.valueOf(i));
			} else if (String.valueOf(i).contains("3")) {
				sb.append(' ').append(String.valueOf(i));
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if (i % 3 == 0) {
				sb.append(' ').append(String.valueOf(i));
			} else if (String.valueOf(i).contains("3")) {
				sb.append(' ').append(String.valueOf(i));
			}
		} {
			if (i % 3 == 0) {
				sb.append(' ').append(String.valueOf(i));
			} else if (String.valueOf(i).contains("3")) {
				sb.append(' ').append(String.valueOf(i));
			}
		} if (i % 3 == 0) {
				sb.append(' ').append(String.valueOf(i));
			} else if (String.valueOf(i).contains("3")) {
				sb.append(' ').append(String.valueOf(i));
			} i % 3 == 0 i % 3 i 3 0 {
				sb.append(' ').append(String.valueOf(i));
			} sb.append(' ').append(String.valueOf(i)) sb.append(' ').append sb.append(' ') sb.append sb ' ' String.valueOf(i) String.valueOf String i if (String.valueOf(i).contains("3")) {
				sb.append(' ').append(String.valueOf(i));
			} String.valueOf(i).contains("3") String.valueOf(i).contains String.valueOf(i) String.valueOf String i "3" {
				sb.append(' ').append(String.valueOf(i));
			} sb.append(' ').append(String.valueOf(i)) sb.append(' ').append sb.append(' ') sb.append sb ' ' String.valueOf(i) String.valueOf String i return sb.toString(); sb.toString() sb.toString sb int n n public class Main {
	public static void main(String[] args) {
		try (Scanner stdin = new Scanner(System.in)) {
			int n = Integer.parseInt(stdin.next());
			if (n < 3 || n > 10000) {
				throw new RuntimeException("Input Range:between 3 and 10000");
			}
			System.out.println(checkNum(n));

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static String checkNum(int n) {
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(' ').append(String.valueOf(i));
			} else if (String.valueOf(i).contains("3")) {
				sb.append(' ').append(String.valueOf(i));
			}
		}
		return sb.toString();
	}
} public class Main {
	public static void main(String[] args) {
		try (Scanner stdin = new Scanner(System.in)) {
			int n = Integer.parseInt(stdin.next());
			if (n < 3 || n > 10000) {
				throw new RuntimeException("Input Range:between 3 and 10000");
			}
			System.out.println(checkNum(n));

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static String checkNum(int n) {
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(' ').append(String.valueOf(i));
			} else if (String.valueOf(i).contains("3")) {
				sb.append(' ').append(String.valueOf(i));
			}
		}
		return sb.toString();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner stdin = new Scanner(System.in)) {
			int n = Integer.parseInt(stdin.next());
			if (n < 3 || n > 10000) {
				throw new RuntimeException("Input Range:between 3 and 10000");
			}
			System.out.println(checkNum(n));

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static String checkNum(int n) {
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(' ').append(String.valueOf(i));
			} else if (String.valueOf(i).contains("3")) {
				sb.append(' ').append(String.valueOf(i));
			}
		}
		return sb.toString();
	}
}