import java.io.*;
import java.util.Scanner;

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

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