
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
			int n, cnt;
			Scanner sc = new Scanner(System.in);
			n = sc.nextInt();
			for(cnt = 3; cnt < n; cnt++){
				if(cnt % 3 == 0 || String.valueOf(cnt).contains("3"))
					System.out.print(" " + cnt);
			}
			
			if(n % 3 == 0)
				System.out.println(" " + n);
			else
				System.out.print("\n");
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
			int n, cnt;
			Scanner sc = new Scanner(System.in);
			n = sc.nextInt();
			for(cnt = 3; cnt < n; cnt++){
				if(cnt % 3 == 0 || String.valueOf(cnt).contains("3"))
					System.out.print(" " + cnt);
			}
			
			if(n % 3 == 0)
				System.out.println(" " + n);
			else
				System.out.print("\n");
	}
} Main public static void main(String[] args) {
			int n, cnt;
			Scanner sc = new Scanner(System.in);
			n = sc.nextInt();
			for(cnt = 3; cnt < n; cnt++){
				if(cnt % 3 == 0 || String.valueOf(cnt).contains("3"))
					System.out.print(" " + cnt);
			}
			
			if(n % 3 == 0)
				System.out.println(" " + n);
			else
				System.out.print("\n");
	} main {
			int n, cnt;
			Scanner sc = new Scanner(System.in);
			n = sc.nextInt();
			for(cnt = 3; cnt < n; cnt++){
				if(cnt % 3 == 0 || String.valueOf(cnt).contains("3"))
					System.out.print(" " + cnt);
			}
			
			if(n % 3 == 0)
				System.out.println(" " + n);
			else
				System.out.print("\n");
	} int n n cnt; cnt Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc for(cnt = 3; cnt < n; cnt++){
				if(cnt % 3 == 0 || String.valueOf(cnt).contains("3"))
					System.out.print(" " + cnt);
			} cnt = 3; cnt = 3 cnt 3 cnt < n cnt n cnt++ cnt++ cnt {
				if(cnt % 3 == 0 || String.valueOf(cnt).contains("3"))
					System.out.print(" " + cnt);
			} {
				if(cnt % 3 == 0 || String.valueOf(cnt).contains("3"))
					System.out.print(" " + cnt);
			} if(cnt % 3 == 0 || String.valueOf(cnt).contains("3"))
					System.out.print(" " + cnt); cnt % 3 == 0 || String.valueOf(cnt).contains("3") cnt % 3 == 0 cnt % 3 cnt 3 0 String.valueOf(cnt).contains("3") String.valueOf(cnt).contains String.valueOf(cnt) String.valueOf String cnt "3" System.out.print(" " + cnt) System.out.print System.out System System.out " " + cnt " " cnt if(n % 3 == 0)
				System.out.println(" " + n);
			else
				System.out.print("\n"); n % 3 == 0 n % 3 n 3 0 System.out.println(" " + n) System.out.println System.out System System.out " " + n " " n System.out.print("\n") System.out.print System.out System System.out "\n" String[] args args public class Main {
	public static void main(String[] args) {
			int n, cnt;
			Scanner sc = new Scanner(System.in);
			n = sc.nextInt();
			for(cnt = 3; cnt < n; cnt++){
				if(cnt % 3 == 0 || String.valueOf(cnt).contains("3"))
					System.out.print(" " + cnt);
			}
			
			if(n % 3 == 0)
				System.out.println(" " + n);
			else
				System.out.print("\n");
	}
} public class Main {
	public static void main(String[] args) {
			int n, cnt;
			Scanner sc = new Scanner(System.in);
			n = sc.nextInt();
			for(cnt = 3; cnt < n; cnt++){
				if(cnt % 3 == 0 || String.valueOf(cnt).contains("3"))
					System.out.print(" " + cnt);
			}
			
			if(n % 3 == 0)
				System.out.println(" " + n);
			else
				System.out.print("\n");
	}
} Main

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
			int n, cnt;
			Scanner sc = new Scanner(System.in);
			n = sc.nextInt();
			for(cnt = 3; cnt < n; cnt++){
				if(cnt % 3 == 0 || String.valueOf(cnt).contains("3"))
					System.out.print(" " + cnt);
			}
			
			if(n % 3 == 0)
				System.out.println(" " + n);
			else
				System.out.print("\n");
	}
}