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

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

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

	    }
	  
	}
	System.out.println("");
    } main {
	final Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	int count=0;
	System.out.print(" ");
	for(int i=1;i<=n;i++){
	    int num=i;
	    if(num%3==0) {
		if(count==0) System.out.print(i);
		else System.out.print(" "+i);
		count++;
	    }
	    else {
		while(num!=0){
		    if(num%10==3){
			if(count==0) System.out.print(i);
			else System.out.print(" "+i);
			count++;
			break;
		    }
		    num/=10;
		}

	    }
	  
	}
	System.out.println("");
    } final Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int count=0; count 0 System.out.print(" ") System.out.print System.out System System.out " " for(int i=1;i<=n;i++){
	    int num=i;
	    if(num%3==0) {
		if(count==0) System.out.print(i);
		else System.out.print(" "+i);
		count++;
	    }
	    else {
		while(num!=0){
		    if(num%10==3){
			if(count==0) System.out.print(i);
			else System.out.print(" "+i);
			count++;
			break;
		    }
		    num/=10;
		}

	    }
	  
	} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
	    int num=i;
	    if(num%3==0) {
		if(count==0) System.out.print(i);
		else System.out.print(" "+i);
		count++;
	    }
	    else {
		while(num!=0){
		    if(num%10==3){
			if(count==0) System.out.print(i);
			else System.out.print(" "+i);
			count++;
			break;
		    }
		    num/=10;
		}

	    }
	  
	} {
	    int num=i;
	    if(num%3==0) {
		if(count==0) System.out.print(i);
		else System.out.print(" "+i);
		count++;
	    }
	    else {
		while(num!=0){
		    if(num%10==3){
			if(count==0) System.out.print(i);
			else System.out.print(" "+i);
			count++;
			break;
		    }
		    num/=10;
		}

	    }
	  
	} int num=i; num i if(num%3==0) {
		if(count==0) System.out.print(i);
		else System.out.print(" "+i);
		count++;
	    }
	    else {
		while(num!=0){
		    if(num%10==3){
			if(count==0) System.out.print(i);
			else System.out.print(" "+i);
			count++;
			break;
		    }
		    num/=10;
		}

	    } num%3==0 num%3 num 3 0 {
		if(count==0) System.out.print(i);
		else System.out.print(" "+i);
		count++;
	    } if(count==0) System.out.print(i);
		else System.out.print(" "+i); count==0 count 0 System.out.print(i) System.out.print System.out System System.out i System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i count++ count {
		while(num!=0){
		    if(num%10==3){
			if(count==0) System.out.print(i);
			else System.out.print(" "+i);
			count++;
			break;
		    }
		    num/=10;
		}

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

	    }
	  
	}
	System.out.println("");
    }
}