import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = 0;
		for(int i=3; i<=n; i++){
			a=i;
			for(;;){
				if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				}
				if(a<10)break;
				a=a/10;
			}
		}
		System.out.println();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = 0;
		for(int i=3; i<=n; i++){
			a=i;
			for(;;){
				if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				}
				if(a<10)break;
				a=a/10;
			}
		}
		System.out.println();
	}
} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = 0;
		for(int i=3; i<=n; i++){
			a=i;
			for(;;){
				if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				}
				if(a<10)break;
				a=a/10;
			}
		}
		System.out.println();
	} main {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = 0;
		for(int i=3; i<=n; i++){
			a=i;
			for(;;){
				if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				}
				if(a<10)break;
				a=a/10;
			}
		}
		System.out.println();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int a = 0; a 0 for(int i=3; i<=n; i++){
			a=i;
			for(;;){
				if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				}
				if(a<10)break;
				a=a/10;
			}
		} int i=3; int i=3; i 3 i<=n i n i++ i++ i {
			a=i;
			for(;;){
				if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				}
				if(a<10)break;
				a=a/10;
			}
		} {
			a=i;
			for(;;){
				if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				}
				if(a<10)break;
				a=a/10;
			}
		} a=i a i for(;;){
				if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				}
				if(a<10)break;
				a=a/10;
			} ; {
				if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				}
				if(a<10)break;
				a=a/10;
			} {
				if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				}
				if(a<10)break;
				a=a/10;
			} if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				} i%3==0 || a%10==3 i%3==0 i%3 i 3 0 a%10==3 a%10 a 10 3 {
				System.out.print(" " + i);
				break;
				} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i break; if(a<10)break; a<10 a 10 break; a=a/10 a a/10 a 10 System.out.println() System.out.println System.out System System.out String[] args args public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = 0;
		for(int i=3; i<=n; i++){
			a=i;
			for(;;){
				if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				}
				if(a<10)break;
				a=a/10;
			}
		}
		System.out.println();
	}
} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = 0;
		for(int i=3; i<=n; i++){
			a=i;
			for(;;){
				if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				}
				if(a<10)break;
				a=a/10;
			}
		}
		System.out.println();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = 0;
		for(int i=3; i<=n; i++){
			a=i;
			for(;;){
				if(i%3==0 || a%10==3){
				System.out.print(" " + i);
				break;
				}
				if(a<10)break;
				a=a/10;
			}
		}
		System.out.println();
	}
}