import java.util.Scanner;

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

        for(int i=1; i<=n; i++) {
            if(i % 3 == 0) {
                System.out.print(" " + i);
            } else{
            	for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	}
            }
        }
        System.out.print("\n");
        sc.close();
    }
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for(int i=1; i<=n; i++) {
            if(i % 3 == 0) {
                System.out.print(" " + i);
            } else{
            	for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	}
            }
        }
        System.out.print("\n");
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for(int i=1; i<=n; i++) {
            if(i % 3 == 0) {
                System.out.print(" " + i);
            } else{
            	for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	}
            }
        }
        System.out.print("\n");
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for(int i=1; i<=n; i++) {
            if(i % 3 == 0) {
                System.out.print(" " + i);
            } else{
            	for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	}
            }
        }
        System.out.print("\n");
        sc.close();
    } 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++) {
            if(i % 3 == 0) {
                System.out.print(" " + i);
            } else{
            	for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	}
            }
        } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
            if(i % 3 == 0) {
                System.out.print(" " + i);
            } else{
            	for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	}
            }
        } {
            if(i % 3 == 0) {
                System.out.print(" " + i);
            } else{
            	for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	}
            }
        } if(i % 3 == 0) {
                System.out.print(" " + i);
            } else{
            	for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	}
            } i % 3 == 0 i % 3 i 3 0 {
                System.out.print(" " + i);
            } System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
            	for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	}
            } for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	} int j=i; int j=i; j i j>0 j 0 j/=10 j/=10 j 10 {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	} {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	} if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    } j % 10 == 3 j % 10 j 10 3 {
                        System.out.print(" " + i);
                        break;
                    } System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i break; System.out.print("\n") System.out.print System.out System System.out "\n" sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for(int i=1; i<=n; i++) {
            if(i % 3 == 0) {
                System.out.print(" " + i);
            } else{
            	for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	}
            }
        }
        System.out.print("\n");
        sc.close();
    }
} public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for(int i=1; i<=n; i++) {
            if(i % 3 == 0) {
                System.out.print(" " + i);
            } else{
            	for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	}
            }
        }
        System.out.print("\n");
        sc.close();
    }
} Main
import java.util.Scanner;

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

        for(int i=1; i<=n; i++) {
            if(i % 3 == 0) {
                System.out.print(" " + i);
            } else{
            	for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	}
            }
        }
        System.out.print("\n");
        sc.close();
    }
}