import java.util.Scanner;

public class Main {
	 public static void main(String[] args) {
	        StringBuilder count=new StringBuilder();
	        Scanner sc=new Scanner(System.in);
	        int n=sc.nextInt();
	        for (int i=1;i<=n;i++){
	            int x=i;
	            if (x%3==0){
	                count.append(" "+i);
	                continue;}
	            do{
	                if(x%10==3){
	                    count.append(" "+i);
	                    break;}
	                x/=10;
	            }while(x!=0);
	        }
	        System.out.println(count);
	    }
	}
 import java.util.Scanner; Scanner java.util public class Main {
	 public static void main(String[] args) {
	        StringBuilder count=new StringBuilder();
	        Scanner sc=new Scanner(System.in);
	        int n=sc.nextInt();
	        for (int i=1;i<=n;i++){
	            int x=i;
	            if (x%3==0){
	                count.append(" "+i);
	                continue;}
	            do{
	                if(x%10==3){
	                    count.append(" "+i);
	                    break;}
	                x/=10;
	            }while(x!=0);
	        }
	        System.out.println(count);
	    }
	} Main public static void main(String[] args) {
	        StringBuilder count=new StringBuilder();
	        Scanner sc=new Scanner(System.in);
	        int n=sc.nextInt();
	        for (int i=1;i<=n;i++){
	            int x=i;
	            if (x%3==0){
	                count.append(" "+i);
	                continue;}
	            do{
	                if(x%10==3){
	                    count.append(" "+i);
	                    break;}
	                x/=10;
	            }while(x!=0);
	        }
	        System.out.println(count);
	    } main {
	        StringBuilder count=new StringBuilder();
	        Scanner sc=new Scanner(System.in);
	        int n=sc.nextInt();
	        for (int i=1;i<=n;i++){
	            int x=i;
	            if (x%3==0){
	                count.append(" "+i);
	                continue;}
	            do{
	                if(x%10==3){
	                    count.append(" "+i);
	                    break;}
	                x/=10;
	            }while(x!=0);
	        }
	        System.out.println(count);
	    } StringBuilder count=new StringBuilder(); count new StringBuilder() 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){
	                count.append(" "+i);
	                continue;}
	            do{
	                if(x%10==3){
	                    count.append(" "+i);
	                    break;}
	                x/=10;
	            }while(x!=0);
	        } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
	            int x=i;
	            if (x%3==0){
	                count.append(" "+i);
	                continue;}
	            do{
	                if(x%10==3){
	                    count.append(" "+i);
	                    break;}
	                x/=10;
	            }while(x!=0);
	        } {
	            int x=i;
	            if (x%3==0){
	                count.append(" "+i);
	                continue;}
	            do{
	                if(x%10==3){
	                    count.append(" "+i);
	                    break;}
	                x/=10;
	            }while(x!=0);
	        } int x=i; x i if (x%3==0){
	                count.append(" "+i);
	                continue;} x%3==0 x%3 x 3 0 {
	                count.append(" "+i);
	                continue;} count.append(" "+i) count.append count " "+i " " i continue; do{
	                if(x%10==3){
	                    count.append(" "+i);
	                    break;}
	                x/=10;
	            }while(x!=0); x!=0 x 0 {
	                if(x%10==3){
	                    count.append(" "+i);
	                    break;}
	                x/=10;
	            } if(x%10==3){
	                    count.append(" "+i);
	                    break;} x%10==3 x%10 x 10 3 {
	                    count.append(" "+i);
	                    break;} count.append(" "+i) count.append count " "+i " " i break; x/=10 x 10 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
	 public static void main(String[] args) {
	        StringBuilder count=new StringBuilder();
	        Scanner sc=new Scanner(System.in);
	        int n=sc.nextInt();
	        for (int i=1;i<=n;i++){
	            int x=i;
	            if (x%3==0){
	                count.append(" "+i);
	                continue;}
	            do{
	                if(x%10==3){
	                    count.append(" "+i);
	                    break;}
	                x/=10;
	            }while(x!=0);
	        }
	        System.out.println(count);
	    }
	} public class Main {
	 public static void main(String[] args) {
	        StringBuilder count=new StringBuilder();
	        Scanner sc=new Scanner(System.in);
	        int n=sc.nextInt();
	        for (int i=1;i<=n;i++){
	            int x=i;
	            if (x%3==0){
	                count.append(" "+i);
	                continue;}
	            do{
	                if(x%10==3){
	                    count.append(" "+i);
	                    break;}
	                x/=10;
	            }while(x!=0);
	        }
	        System.out.println(count);
	    }
	} Main
import java.util.Scanner;

public class Main {
	 public static void main(String[] args) {
	        StringBuilder count=new StringBuilder();
	        Scanner sc=new Scanner(System.in);
	        int n=sc.nextInt();
	        for (int i=1;i<=n;i++){
	            int x=i;
	            if (x%3==0){
	                count.append(" "+i);
	                continue;}
	            do{
	                if(x%10==3){
	                    count.append(" "+i);
	                    break;}
	                x/=10;
	            }while(x!=0);
	        }
	        System.out.println(count);
	    }
	}

