import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public void exec() throws IOException {
        Scanner input = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = input.nextInt();
        StringBuilder sb = new StringBuilder();
        for(int i=1; i<=n; i++){
        	if(i%3==0 || appearance3(i)) {
        		sb.append(" ").append(i);
        	}
        }
        out.println(sb.toString());
        out.flush();
        input.close();
    }
    
    private boolean appearance3(int num) {
    	for(;num>0; num/=10) {
    		if(num % 10 == 3) return true;
    	}
    	return false;
    }
 
    public static void main(String[] args) throws IOException {
    	new Main().exec();
    }

}
  import java.io.IOException; IOException java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
    public void exec() throws IOException {
        Scanner input = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = input.nextInt();
        StringBuilder sb = new StringBuilder();
        for(int i=1; i<=n; i++){
        	if(i%3==0 || appearance3(i)) {
        		sb.append(" ").append(i);
        	}
        }
        out.println(sb.toString());
        out.flush();
        input.close();
    }
    
    private boolean appearance3(int num) {
    	for(;num>0; num/=10) {
    		if(num % 10 == 3) return true;
    	}
    	return false;
    }
 
    public static void main(String[] args) throws IOException {
    	new Main().exec();
    }

} Main public void exec() throws IOException {
        Scanner input = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = input.nextInt();
        StringBuilder sb = new StringBuilder();
        for(int i=1; i<=n; i++){
        	if(i%3==0 || appearance3(i)) {
        		sb.append(" ").append(i);
        	}
        }
        out.println(sb.toString());
        out.flush();
        input.close();
    } exec {
        Scanner input = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = input.nextInt();
        StringBuilder sb = new StringBuilder();
        for(int i=1; i<=n; i++){
        	if(i%3==0 || appearance3(i)) {
        		sb.append(" ").append(i);
        	}
        }
        out.println(sb.toString());
        out.flush();
        input.close();
    } Scanner input = new Scanner(System.in); input new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int n = input.nextInt(); n input.nextInt() input.nextInt input StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i=1; i<=n; i++){
        	if(i%3==0 || appearance3(i)) {
        		sb.append(" ").append(i);
        	}
        } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
        	if(i%3==0 || appearance3(i)) {
        		sb.append(" ").append(i);
        	}
        } {
        	if(i%3==0 || appearance3(i)) {
        		sb.append(" ").append(i);
        	}
        } if(i%3==0 || appearance3(i)) {
        		sb.append(" ").append(i);
        	} i%3==0 || appearance3(i) i%3==0 i%3 i 3 0 appearance3(i) appearance3 i {
        		sb.append(" ").append(i);
        	} sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i out.println(sb.toString()) out.println out sb.toString() sb.toString sb out.flush() out.flush out input.close() input.close input private boolean appearance3(int num) {
    	for(;num>0; num/=10) {
    		if(num % 10 == 3) return true;
    	}
    	return false;
    } appearance3 {
    	for(;num>0; num/=10) {
    		if(num % 10 == 3) return true;
    	}
    	return false;
    } for(;num>0; num/=10) {
    		if(num % 10 == 3) return true;
    	} ; num>0 num 0 num/=10 num/=10 num 10 {
    		if(num % 10 == 3) return true;
    	} {
    		if(num % 10 == 3) return true;
    	} if(num % 10 == 3) return true; num % 10 == 3 num % 10 num 10 3 return true; true return false; false int num num public static void main(String[] args) throws IOException {
    	new Main().exec();
    } main {
    	new Main().exec();
    } new Main().exec() new Main().exec new Main() String[] args args public class Main {
    public void exec() throws IOException {
        Scanner input = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = input.nextInt();
        StringBuilder sb = new StringBuilder();
        for(int i=1; i<=n; i++){
        	if(i%3==0 || appearance3(i)) {
        		sb.append(" ").append(i);
        	}
        }
        out.println(sb.toString());
        out.flush();
        input.close();
    }
    
    private boolean appearance3(int num) {
    	for(;num>0; num/=10) {
    		if(num % 10 == 3) return true;
    	}
    	return false;
    }
 
    public static void main(String[] args) throws IOException {
    	new Main().exec();
    }

} public class Main {
    public void exec() throws IOException {
        Scanner input = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = input.nextInt();
        StringBuilder sb = new StringBuilder();
        for(int i=1; i<=n; i++){
        	if(i%3==0 || appearance3(i)) {
        		sb.append(" ").append(i);
        	}
        }
        out.println(sb.toString());
        out.flush();
        input.close();
    }
    
    private boolean appearance3(int num) {
    	for(;num>0; num/=10) {
    		if(num % 10 == 3) return true;
    	}
    	return false;
    }
 
    public static void main(String[] args) throws IOException {
    	new Main().exec();
    }

} Main
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public void exec() throws IOException {
        Scanner input = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = input.nextInt();
        StringBuilder sb = new StringBuilder();
        for(int i=1; i<=n; i++){
        	if(i%3==0 || appearance3(i)) {
        		sb.append(" ").append(i);
        	}
        }
        out.println(sb.toString());
        out.flush();
        input.close();
    }
    
    private boolean appearance3(int num) {
    	for(;num>0; num/=10) {
    		if(num % 10 == 3) return true;
    	}
    	return false;
    }
 
    public static void main(String[] args) throws IOException {
    	new Main().exec();
    }

}
 