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

public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                int n = Integer.parseInt(line);
                call(n);
                
            }
            stdReader.close();
        } catch(Exception e) {
            e.getStackTrace();
            System.exit(-1);
        }
    }
    
    private static void call(int n) {
        int x;
        for(int i = 1; i <= n; i++) {
            x = i;
            if(x % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while(x != 0) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    
                    break;
                }
                x /= 10;
            }
        }
        System.out.println();
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                int n = Integer.parseInt(line);
                call(n);
                
            }
            stdReader.close();
        } catch(Exception e) {
            e.getStackTrace();
            System.exit(-1);
        }
    }
    
    private static void call(int n) {
        int x;
        for(int i = 1; i <= n; i++) {
            x = i;
            if(x % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while(x != 0) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    
                    break;
                }
                x /= 10;
            }
        }
        System.out.println();
    }
} Main public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                int n = Integer.parseInt(line);
                call(n);
                
            }
            stdReader.close();
        } catch(Exception e) {
            e.getStackTrace();
            System.exit(-1);
        }
    } main {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                int n = Integer.parseInt(line);
                call(n);
                
            }
            stdReader.close();
        } catch(Exception e) {
            e.getStackTrace();
            System.exit(-1);
        }
    } try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                int n = Integer.parseInt(line);
                call(n);
                
            }
            stdReader.close();
        } catch(Exception e) {
            e.getStackTrace();
            System.exit(-1);
        } catch(Exception e) {
            e.getStackTrace();
            System.exit(-1);
        } Exception e {
            e.getStackTrace();
            System.exit(-1);
        } e.getStackTrace() e.getStackTrace e System.exit(-1) System.exit System -1 1 {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                int n = Integer.parseInt(line);
                call(n);
                
            }
            stdReader.close();
        } BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in)); stdReader new BufferedReader(new InputStreamReader(System.in)) String line; line while((line = stdReader.readLine()) != null) {
                int n = Integer.parseInt(line);
                call(n);
                
            } (line = stdReader.readLine()) != null (line = stdReader.readLine()) line stdReader.readLine() stdReader.readLine stdReader null {
                int n = Integer.parseInt(line);
                call(n);
                
            } int n = Integer.parseInt(line); n Integer.parseInt(line) Integer.parseInt Integer line call(n) call n stdReader.close() stdReader.close stdReader String[] args args private static void call(int n) {
        int x;
        for(int i = 1; i <= n; i++) {
            x = i;
            if(x % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while(x != 0) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    
                    break;
                }
                x /= 10;
            }
        }
        System.out.println();
    } call {
        int x;
        for(int i = 1; i <= n; i++) {
            x = i;
            if(x % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while(x != 0) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    
                    break;
                }
                x /= 10;
            }
        }
        System.out.println();
    } int x; x for(int i = 1; i <= n; i++) {
            x = i;
            if(x % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while(x != 0) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    
                    break;
                }
                x /= 10;
            }
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            x = i;
            if(x % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while(x != 0) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    
                    break;
                }
                x /= 10;
            }
        } {
            x = i;
            if(x % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while(x != 0) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    
                    break;
                }
                x /= 10;
            }
        } x = i x i if(x % 3 == 0) {
                System.out.print(" " + i);
                continue;
            } x % 3 == 0 x % 3 x 3 0 {
                System.out.print(" " + i);
                continue;
            } System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i continue; while(x != 0) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    
                    break;
                }
                x /= 10;
            } x != 0 x 0 {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    
                    break;
                }
                x /= 10;
            } if(x % 10 == 3) {
                    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; x /= 10 x 10 System.out.println() System.out.println System.out System System.out int n n public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                int n = Integer.parseInt(line);
                call(n);
                
            }
            stdReader.close();
        } catch(Exception e) {
            e.getStackTrace();
            System.exit(-1);
        }
    }
    
    private static void call(int n) {
        int x;
        for(int i = 1; i <= n; i++) {
            x = i;
            if(x % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while(x != 0) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    
                    break;
                }
                x /= 10;
            }
        }
        System.out.println();
    }
} public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                int n = Integer.parseInt(line);
                call(n);
                
            }
            stdReader.close();
        } catch(Exception e) {
            e.getStackTrace();
            System.exit(-1);
        }
    }
    
    private static void call(int n) {
        int x;
        for(int i = 1; i <= n; i++) {
            x = i;
            if(x % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while(x != 0) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    
                    break;
                }
                x /= 10;
            }
        }
        System.out.println();
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                int n = Integer.parseInt(line);
                call(n);
                
            }
            stdReader.close();
        } catch(Exception e) {
            e.getStackTrace();
            System.exit(-1);
        }
    }
    
    private static void call(int n) {
        int x;
        for(int i = 1; i <= n; i++) {
            x = i;
            if(x % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while(x != 0) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    
                    break;
                }
                x /= 10;
            }
        }
        System.out.println();
    }
}