import java.io.IOException;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
          Scanner sc = new Scanner(System.in);
          int n = sc.nextInt();
          int a;
          int b = 1;
          while(b<=n){
        	  a=b;
             if(a%3 == 0){
        	     System.out.print(" "+b);
             }
             else{
            	 while(a != 0){
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 }
             }
             b=b+1;
          }
          System.out.println();
	}

} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
          Scanner sc = new Scanner(System.in);
          int n = sc.nextInt();
          int a;
          int b = 1;
          while(b<=n){
        	  a=b;
             if(a%3 == 0){
        	     System.out.print(" "+b);
             }
             else{
            	 while(a != 0){
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 }
             }
             b=b+1;
          }
          System.out.println();
	}

} Main public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
          Scanner sc = new Scanner(System.in);
          int n = sc.nextInt();
          int a;
          int b = 1;
          while(b<=n){
        	  a=b;
             if(a%3 == 0){
        	     System.out.print(" "+b);
             }
             else{
            	 while(a != 0){
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 }
             }
             b=b+1;
          }
          System.out.println();
	} main {
		// TODO ?????????????????????????????????????????????
          Scanner sc = new Scanner(System.in);
          int n = sc.nextInt();
          int a;
          int b = 1;
          while(b<=n){
        	  a=b;
             if(a%3 == 0){
        	     System.out.print(" "+b);
             }
             else{
            	 while(a != 0){
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 }
             }
             b=b+1;
          }
          System.out.println();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int a; a int b = 1; b 1 while(b<=n){
        	  a=b;
             if(a%3 == 0){
        	     System.out.print(" "+b);
             }
             else{
            	 while(a != 0){
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 }
             }
             b=b+1;
          } b<=n b n {
        	  a=b;
             if(a%3 == 0){
        	     System.out.print(" "+b);
             }
             else{
            	 while(a != 0){
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 }
             }
             b=b+1;
          } a=b a b if(a%3 == 0){
        	     System.out.print(" "+b);
             }
             else{
            	 while(a != 0){
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 }
             } a%3 == 0 a%3 a 3 0 {
        	     System.out.print(" "+b);
             } System.out.print(" "+b) System.out.print System.out System System.out " "+b " " b {
            	 while(a != 0){
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 }
             } while(a != 0){
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 } a != 0 a 0 {
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 } if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 } a%10 == 3 a%10 a 10 3 {
            			 System.out.print(" "+b);
            			 break;
            		 } System.out.print(" "+b) System.out.print System.out System System.out " "+b " " b break; a = a/10 a a/10 a 10 b=b+1 b b+1 b 1 System.out.println() System.out.println System.out System System.out String[] args args public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
          Scanner sc = new Scanner(System.in);
          int n = sc.nextInt();
          int a;
          int b = 1;
          while(b<=n){
        	  a=b;
             if(a%3 == 0){
        	     System.out.print(" "+b);
             }
             else{
            	 while(a != 0){
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 }
             }
             b=b+1;
          }
          System.out.println();
	}

} public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
          Scanner sc = new Scanner(System.in);
          int n = sc.nextInt();
          int a;
          int b = 1;
          while(b<=n){
        	  a=b;
             if(a%3 == 0){
        	     System.out.print(" "+b);
             }
             else{
            	 while(a != 0){
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 }
             }
             b=b+1;
          }
          System.out.println();
	}

} Main
import java.io.IOException;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
          Scanner sc = new Scanner(System.in);
          int n = sc.nextInt();
          int a;
          int b = 1;
          while(b<=n){
        	  a=b;
             if(a%3 == 0){
        	     System.out.print(" "+b);
             }
             else{
            	 while(a != 0){
            		 if(a%10 == 3){
            			 System.out.print(" "+b);
            			 break;
            		 }
            		 a = a/10;
            	 }
             }
             b=b+1;
          }
          System.out.println();
	}

}