import java.util.*; 

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt();
		int i=1;
		while(i<=n){
			int x=i;
			
			if(x%3==0){
				System.out.print(" "+i);
			}
			else include3(x,i);
			i++;
		}
		System.out.println();

	}
	
	static void include3(int x,int i){
		if(x%10==3){
			System.out.print(" "+i);
			return;
		}
		x/=10;
		if(x>=1)include3(x,i);
	}

}
 import java.util.*; util.* java public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt();
		int i=1;
		while(i<=n){
			int x=i;
			
			if(x%3==0){
				System.out.print(" "+i);
			}
			else include3(x,i);
			i++;
		}
		System.out.println();

	}
	
	static void include3(int x,int i){
		if(x%10==3){
			System.out.print(" "+i);
			return;
		}
		x/=10;
		if(x>=1)include3(x,i);
	}

} Main /**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt();
		int i=1;
		while(i<=n){
			int x=i;
			
			if(x%3==0){
				System.out.print(" "+i);
			}
			else include3(x,i);
			i++;
		}
		System.out.println();

	} main {
		// TODO Auto-generated method stub
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt();
		int i=1;
		while(i<=n){
			int x=i;
			
			if(x%3==0){
				System.out.print(" "+i);
			}
			else include3(x,i);
			i++;
		}
		System.out.println();

	} Scanner cin=new Scanner(System.in); cin new Scanner(System.in) int n=cin.nextInt(); n cin.nextInt() cin.nextInt cin int i=1; i 1 while(i<=n){
			int x=i;
			
			if(x%3==0){
				System.out.print(" "+i);
			}
			else include3(x,i);
			i++;
		} i<=n i n {
			int x=i;
			
			if(x%3==0){
				System.out.print(" "+i);
			}
			else include3(x,i);
			i++;
		} int x=i; x i if(x%3==0){
				System.out.print(" "+i);
			}
			else include3(x,i); x%3==0 x%3 x 3 0 {
				System.out.print(" "+i);
			} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i include3(x,i) include3 x i i++ i System.out.println() System.out.println System.out System System.out String[] args args static void include3(int x,int i){
		if(x%10==3){
			System.out.print(" "+i);
			return;
		}
		x/=10;
		if(x>=1)include3(x,i);
	} include3 {
		if(x%10==3){
			System.out.print(" "+i);
			return;
		}
		x/=10;
		if(x>=1)include3(x,i);
	} if(x%10==3){
			System.out.print(" "+i);
			return;
		} x%10==3 x%10 x 10 3 {
			System.out.print(" "+i);
			return;
		} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i return; x/=10 x 10 if(x>=1)include3(x,i); x>=1 x 1 include3(x,i) include3 x i int x x int i i public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt();
		int i=1;
		while(i<=n){
			int x=i;
			
			if(x%3==0){
				System.out.print(" "+i);
			}
			else include3(x,i);
			i++;
		}
		System.out.println();

	}
	
	static void include3(int x,int i){
		if(x%10==3){
			System.out.print(" "+i);
			return;
		}
		x/=10;
		if(x>=1)include3(x,i);
	}

} public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt();
		int i=1;
		while(i<=n){
			int x=i;
			
			if(x%3==0){
				System.out.print(" "+i);
			}
			else include3(x,i);
			i++;
		}
		System.out.println();

	}
	
	static void include3(int x,int i){
		if(x%10==3){
			System.out.print(" "+i);
			return;
		}
		x/=10;
		if(x>=1)include3(x,i);
	}

} Main
import java.util.*; 

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt();
		int i=1;
		while(i<=n){
			int x=i;
			
			if(x%3==0){
				System.out.print(" "+i);
			}
			else include3(x,i);
			i++;
		}
		System.out.println();

	}
	
	static void include3(int x,int i){
		if(x%10==3){
			System.out.print(" "+i);
			return;
		}
		x/=10;
		if(x>=1)include3(x,i);
	}

}

