import java.io.IOException;
import java.util.Scanner;
public class Main {
    public static void main (String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int x =sc.nextInt();
        for(int i=1;i<=x;i++){
            int z =i ;
            if(z%3==0){
            	sb.append(" ").append(i);
            }else{
                while(z != 0){
            	    if(z%10 == 3){
            		    sb.append(" ").append(i);
            		    break;
            	    }else{
            	         z /=10;
            	     }
                }
            }

        }
        System.out.println(sb);
        }

    } import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main (String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int x =sc.nextInt();
        for(int i=1;i<=x;i++){
            int z =i ;
            if(z%3==0){
            	sb.append(" ").append(i);
            }else{
                while(z != 0){
            	    if(z%10 == 3){
            		    sb.append(" ").append(i);
            		    break;
            	    }else{
            	         z /=10;
            	     }
                }
            }

        }
        System.out.println(sb);
        }

    } Main public static void main (String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int x =sc.nextInt();
        for(int i=1;i<=x;i++){
            int z =i ;
            if(z%3==0){
            	sb.append(" ").append(i);
            }else{
                while(z != 0){
            	    if(z%10 == 3){
            		    sb.append(" ").append(i);
            		    break;
            	    }else{
            	         z /=10;
            	     }
                }
            }

        }
        System.out.println(sb);
        } main {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int x =sc.nextInt();
        for(int i=1;i<=x;i++){
            int z =i ;
            if(z%3==0){
            	sb.append(" ").append(i);
            }else{
                while(z != 0){
            	    if(z%10 == 3){
            		    sb.append(" ").append(i);
            		    break;
            	    }else{
            	         z /=10;
            	     }
                }
            }

        }
        System.out.println(sb);
        } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int x =sc.nextInt(); x sc.nextInt() sc.nextInt sc for(int i=1;i<=x;i++){
            int z =i ;
            if(z%3==0){
            	sb.append(" ").append(i);
            }else{
                while(z != 0){
            	    if(z%10 == 3){
            		    sb.append(" ").append(i);
            		    break;
            	    }else{
            	         z /=10;
            	     }
                }
            }

        } int i=1; int i=1; i 1 i<=x i x i++ i++ i {
            int z =i ;
            if(z%3==0){
            	sb.append(" ").append(i);
            }else{
                while(z != 0){
            	    if(z%10 == 3){
            		    sb.append(" ").append(i);
            		    break;
            	    }else{
            	         z /=10;
            	     }
                }
            }

        } {
            int z =i ;
            if(z%3==0){
            	sb.append(" ").append(i);
            }else{
                while(z != 0){
            	    if(z%10 == 3){
            		    sb.append(" ").append(i);
            		    break;
            	    }else{
            	         z /=10;
            	     }
                }
            }

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

        }
        System.out.println(sb);
        }

    } public class Main {
    public static void main (String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int x =sc.nextInt();
        for(int i=1;i<=x;i++){
            int z =i ;
            if(z%3==0){
            	sb.append(" ").append(i);
            }else{
                while(z != 0){
            	    if(z%10 == 3){
            		    sb.append(" ").append(i);
            		    break;
            	    }else{
            	         z /=10;
            	     }
                }
            }

        }
        System.out.println(sb);
        }

    } Main
import java.io.IOException;
import java.util.Scanner;
public class Main {
    public static void main (String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int x =sc.nextInt();
        for(int i=1;i<=x;i++){
            int z =i ;
            if(z%3==0){
            	sb.append(" ").append(i);
            }else{
                while(z != 0){
            	    if(z%10 == 3){
            		    sb.append(" ").append(i);
            		    break;
            	    }else{
            	         z /=10;
            	     }
                }
            }

        }
        System.out.println(sb);
        }

    }