import java.util.Scanner;
class Main {
	int x,n = 0,a,b,c,d,e;
	public void pr() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		if(n >= 3 && n <= 10000) {
			for(x = 3; x <= n;x++) {
				a = x % 3;
				b = x % 10;
				c = x / 10;
				d = x / 100;
				e = x / 1000;
				if(a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3) {
					System.out.print(" " + x);
				}
			}
		}
		System.out.println();
	}
	public static void main(String[] args) {
		new Main().pr();
	}
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz