import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0 || Integer.toString(i).indexOf("3") >= 0) {
				System.out.printf(" %d", i);
			}
		}
		System.out.println("");

		scan.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0 || Integer.toString(i).indexOf("3") >= 0) {
				System.out.printf(" %d", i);
			}
		}
		System.out.println("");

		scan.close();
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0 || Integer.toString(i).indexOf("3") >= 0) {
				System.out.printf(" %d", i);
			}
		}
		System.out.println("");

		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0 || Integer.toString(i).indexOf("3") >= 0) {
				System.out.printf(" %d", i);
			}
		}
		System.out.println("");

		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan for(int i = 1; i <= n; i++) {
			if(i % 3 == 0 || Integer.toString(i).indexOf("3") >= 0) {
				System.out.printf(" %d", i);
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if(i % 3 == 0 || Integer.toString(i).indexOf("3") >= 0) {
				System.out.printf(" %d", i);
			}
		} {
			if(i % 3 == 0 || Integer.toString(i).indexOf("3") >= 0) {
				System.out.printf(" %d", i);
			}
		} if(i % 3 == 0 || Integer.toString(i).indexOf("3") >= 0) {
				System.out.printf(" %d", i);
			} i % 3 == 0 || Integer.toString(i).indexOf("3") >= 0 i % 3 == 0 i % 3 i 3 0 Integer.toString(i).indexOf("3") >= 0 Integer.toString(i).indexOf("3") Integer.toString(i).indexOf Integer.toString(i) Integer.toString Integer i "3" 0 {
				System.out.printf(" %d", i);
			} System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i System.out.println("") System.out.println System.out System System.out "" scan.close() scan.close scan String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0 || Integer.toString(i).indexOf("3") >= 0) {
				System.out.printf(" %d", i);
			}
		}
		System.out.println("");

		scan.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0 || Integer.toString(i).indexOf("3") >= 0) {
				System.out.printf(" %d", i);
			}
		}
		System.out.println("");

		scan.close();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0 || Integer.toString(i).indexOf("3") >= 0) {
				System.out.printf(" %d", i);
			}
		}
		System.out.println("");

		scan.close();
	}
}
