import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,s=0,sum=0;
            boolean end=false;
            while ((line = br.readLine()) != null) {
            	n=Integer.parseInt(line);
            	for(int i=1;i<n+1;i++){
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	}
            	System.out.println();
            	break;
            }
        }
    }

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,s=0,sum=0;
            boolean end=false;
            while ((line = br.readLine()) != null) {
            	n=Integer.parseInt(line);
            	for(int i=1;i<n+1;i++){
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	}
            	System.out.println();
            	break;
            }
        }
    }

} Main public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,s=0,sum=0;
            boolean end=false;
            while ((line = br.readLine()) != null) {
            	n=Integer.parseInt(line);
            	for(int i=1;i<n+1;i++){
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	}
            	System.out.println();
            	break;
            }
        }
    } main {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,s=0,sum=0;
            boolean end=false;
            while ((line = br.readLine()) != null) {
            	n=Integer.parseInt(line);
            	for(int i=1;i<n+1;i++){
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	}
            	System.out.println();
            	break;
            }
        }
    } try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,s=0,sum=0;
            boolean end=false;
            while ((line = br.readLine()) != null) {
            	n=Integer.parseInt(line);
            	for(int i=1;i<n+1;i++){
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	}
            	System.out.println();
            	break;
            }
        } {
            String line;
            int n=0,s=0,sum=0;
            boolean end=false;
            while ((line = br.readLine()) != null) {
            	n=Integer.parseInt(line);
            	for(int i=1;i<n+1;i++){
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	}
            	System.out.println();
            	break;
            }
        } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) String line; line int n=0 n 0 s=0 s 0 sum=0; sum 0 boolean end=false; end false while ((line = br.readLine()) != null) {
            	n=Integer.parseInt(line);
            	for(int i=1;i<n+1;i++){
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	}
            	System.out.println();
            	break;
            } (line = br.readLine()) != null (line = br.readLine()) line br.readLine() br.readLine br null {
            	n=Integer.parseInt(line);
            	for(int i=1;i<n+1;i++){
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	}
            	System.out.println();
            	break;
            } n=Integer.parseInt(line) n Integer.parseInt(line) Integer.parseInt Integer line for(int i=1;i<n+1;i++){
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	} int i=1; int i=1; i 1 i<n+1 i n+1 n 1 i++ i++ i {
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	} {
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	} int x=i; x i while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		} true {
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		} if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		} x%10==3 x%10 x 10 3 {
            				System.out.print(" "+i);
            				break;
            			} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i break; if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		} i%3==0 i%3 i 3 0 {
                			System.out.print(" "+i);
                			break;
                		} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i break; x/=10 x 10 if(x==0)break; x==0 x 0 break; System.out.println() System.out.println System.out System System.out break; String[] args args public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,s=0,sum=0;
            boolean end=false;
            while ((line = br.readLine()) != null) {
            	n=Integer.parseInt(line);
            	for(int i=1;i<n+1;i++){
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	}
            	System.out.println();
            	break;
            }
        }
    }

} public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,s=0,sum=0;
            boolean end=false;
            while ((line = br.readLine()) != null) {
            	n=Integer.parseInt(line);
            	for(int i=1;i<n+1;i++){
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	}
            	System.out.println();
            	break;
            }
        }
    }

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,s=0,sum=0;
            boolean end=false;
            while ((line = br.readLine()) != null) {
            	n=Integer.parseInt(line);
            	for(int i=1;i<n+1;i++){
            		int x=i;
            		while(true){
            			if(x%10==3){
            				System.out.print(" "+i);
            				break;
            			}else if(i%3==0){
                			System.out.print(" "+i);
                			break;
                		}
            			x/=10;
            			if(x==0)break;
            		}
            	}
            	System.out.println();
            	break;
            }
        }
    }

}