
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			if (check(i)) {
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.print("\n");
	}

	private static boolean check(int i) {
		if (i % 3 == 0) {
			return true;
		}
		int len = (int) Math.log10(i) + 1;
		int tmp = i;
		for (int j = len - 1; j >= 0; j--) {
			int warikitta = tmp / (int) Math.pow(10, j);
			if (warikitta == 3) {
				return true;
			}
			tmp = tmp - warikitta * (int) Math.pow(10, j);
		}
		return false;
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			if (check(i)) {
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.print("\n");
	}

	private static boolean check(int i) {
		if (i % 3 == 0) {
			return true;
		}
		int len = (int) Math.log10(i) + 1;
		int tmp = i;
		for (int j = len - 1; j >= 0; j--) {
			int warikitta = tmp / (int) Math.pow(10, j);
			if (warikitta == 3) {
				return true;
			}
			tmp = tmp - warikitta * (int) Math.pow(10, j);
		}
		return false;
	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			if (check(i)) {
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.print("\n");
	} main {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			if (check(i)) {
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.print("\n");
	} 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++) {
			if (check(i)) {
				System.out.print(" ");
				System.out.print(i);
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if (check(i)) {
				System.out.print(" ");
				System.out.print(i);
			}
		} {
			if (check(i)) {
				System.out.print(" ");
				System.out.print(i);
			}
		} if (check(i)) {
				System.out.print(" ");
				System.out.print(i);
			} check(i) check i {
				System.out.print(" ");
				System.out.print(i);
			} System.out.print(" ") System.out.print System.out System System.out " " System.out.print(i) System.out.print System.out System System.out i System.out.print("\n") System.out.print System.out System System.out "\n" String[] args args private static boolean check(int i) {
		if (i % 3 == 0) {
			return true;
		}
		int len = (int) Math.log10(i) + 1;
		int tmp = i;
		for (int j = len - 1; j >= 0; j--) {
			int warikitta = tmp / (int) Math.pow(10, j);
			if (warikitta == 3) {
				return true;
			}
			tmp = tmp - warikitta * (int) Math.pow(10, j);
		}
		return false;
	} check {
		if (i % 3 == 0) {
			return true;
		}
		int len = (int) Math.log10(i) + 1;
		int tmp = i;
		for (int j = len - 1; j >= 0; j--) {
			int warikitta = tmp / (int) Math.pow(10, j);
			if (warikitta == 3) {
				return true;
			}
			tmp = tmp - warikitta * (int) Math.pow(10, j);
		}
		return false;
	} if (i % 3 == 0) {
			return true;
		} i % 3 == 0 i % 3 i 3 0 {
			return true;
		} return true; true int len = (int) Math.log10(i) + 1; len (int) Math.log10(i) + 1 (int) Math.log10(i) Math.log10 Math i 1 int tmp = i; tmp i for (int j = len - 1; j >= 0; j--) {
			int warikitta = tmp / (int) Math.pow(10, j);
			if (warikitta == 3) {
				return true;
			}
			tmp = tmp - warikitta * (int) Math.pow(10, j);
		} int j = len - 1; int j = len - 1; j len - 1 len 1 j >= 0 j 0 j-- j-- j {
			int warikitta = tmp / (int) Math.pow(10, j);
			if (warikitta == 3) {
				return true;
			}
			tmp = tmp - warikitta * (int) Math.pow(10, j);
		} {
			int warikitta = tmp / (int) Math.pow(10, j);
			if (warikitta == 3) {
				return true;
			}
			tmp = tmp - warikitta * (int) Math.pow(10, j);
		} int warikitta = tmp / (int) Math.pow(10, j); warikitta tmp / (int) Math.pow(10, j) tmp (int) Math.pow(10, j) Math.pow Math 10 j if (warikitta == 3) {
				return true;
			} warikitta == 3 warikitta 3 {
				return true;
			} return true; true tmp = tmp - warikitta * (int) Math.pow(10, j) tmp tmp - warikitta * (int) Math.pow(10, j) tmp warikitta * (int) Math.pow(10, j) warikitta (int) Math.pow(10, j) Math.pow Math 10 j return false; false int i i public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			if (check(i)) {
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.print("\n");
	}

	private static boolean check(int i) {
		if (i % 3 == 0) {
			return true;
		}
		int len = (int) Math.log10(i) + 1;
		int tmp = i;
		for (int j = len - 1; j >= 0; j--) {
			int warikitta = tmp / (int) Math.pow(10, j);
			if (warikitta == 3) {
				return true;
			}
			tmp = tmp - warikitta * (int) Math.pow(10, j);
		}
		return false;
	}
} public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			if (check(i)) {
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.print("\n");
	}

	private static boolean check(int i) {
		if (i % 3 == 0) {
			return true;
		}
		int len = (int) Math.log10(i) + 1;
		int tmp = i;
		for (int j = len - 1; j >= 0; j--) {
			int warikitta = tmp / (int) Math.pow(10, j);
			if (warikitta == 3) {
				return true;
			}
			tmp = tmp - warikitta * (int) Math.pow(10, j);
		}
		return false;
	}
} Main

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			if (check(i)) {
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.print("\n");
	}

	private static boolean check(int i) {
		if (i % 3 == 0) {
			return true;
		}
		int len = (int) Math.log10(i) + 1;
		int tmp = i;
		for (int j = len - 1; j >= 0; j--) {
			int warikitta = tmp / (int) Math.pow(10, j);
			if (warikitta == 3) {
				return true;
			}
			tmp = tmp - warikitta * (int) Math.pow(10, j);
		}
		return false;
	}
}