import java.util.*;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			print3(x, i);
		}
		System.out.println();
	}

	public static void print3(int x, int i) {
		if (x % 10 == 3) {
			System.out.print(" " + i);
		} else if (x / 10 > 0) {
			print3(x / 10, i);
		}
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			print3(x, i);
		}
		System.out.println();
	}

	public static void print3(int x, int i) {
		if (x % 10 == 3) {
			System.out.print(" " + i);
		} else if (x / 10 > 0) {
			print3(x / 10, i);
		}
	}
} Main public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			print3(x, i);
		}
		System.out.println();
	} main {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			print3(x, i);
		}
		System.out.println();
	} @SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			print3(x, i);
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			print3(x, i);
		} {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			print3(x, i);
		} int x = i; x i if (x % 3 == 0) {
				System.out.print(" " + i);
				continue;
			} x % 3 == 0 x % 3 x 3 0 {
				System.out.print(" " + i);
				continue;
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i continue; print3(x, i) print3 x i System.out.println() System.out.println System.out System System.out String[] args args public static void print3(int x, int i) {
		if (x % 10 == 3) {
			System.out.print(" " + i);
		} else if (x / 10 > 0) {
			print3(x / 10, i);
		}
	} print3 {
		if (x % 10 == 3) {
			System.out.print(" " + i);
		} else if (x / 10 > 0) {
			print3(x / 10, i);
		}
	} if (x % 10 == 3) {
			System.out.print(" " + i);
		} else if (x / 10 > 0) {
			print3(x / 10, i);
		} x % 10 == 3 x % 10 x 10 3 {
			System.out.print(" " + i);
		} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if (x / 10 > 0) {
			print3(x / 10, i);
		} x / 10 > 0 x / 10 x 10 0 {
			print3(x / 10, i);
		} print3(x / 10, i) print3 x / 10 x 10 i int x x int i i public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			print3(x, i);
		}
		System.out.println();
	}

	public static void print3(int x, int i) {
		if (x % 10 == 3) {
			System.out.print(" " + i);
		} else if (x / 10 > 0) {
			print3(x / 10, i);
		}
	}
} public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			print3(x, i);
		}
		System.out.println();
	}

	public static void print3(int x, int i) {
		if (x % 10 == 3) {
			System.out.print(" " + i);
		} else if (x / 10 > 0) {
			print3(x / 10, i);
		}
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			print3(x, i);
		}
		System.out.println();
	}

	public static void print3(int x, int i) {
		if (x % 10 == 3) {
			System.out.print(" " + i);
		} else if (x / 10 > 0) {
			print3(x / 10, i);
		}
	}
}