import java.util.Scanner;
import java.lang.Math;
public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.next());
	call(n);
    }
    public static void call(int n) {
	for (int i = 1; i <= n; i++) {
	    if (i % 3 == 0) {
		System.out.print(" " + i);
		continue;
	    }
	    include3(i);
	}
	System.out.println();
    }
    public static void include3(int i) {
	int x = i;
	while (x > 0) {
	    if (x % 10 == 3) {
		System.out.print(" " + i);
		return;
	    }
	    x /= 10;
	}
    }
} import java.util.Scanner; Scanner java.util import java.lang.Math; Math java.lang public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.next());
	call(n);
    }
    public static void call(int n) {
	for (int i = 1; i <= n; i++) {
	    if (i % 3 == 0) {
		System.out.print(" " + i);
		continue;
	    }
	    include3(i);
	}
	System.out.println();
    }
    public static void include3(int i) {
	int x = i;
	while (x > 0) {
	    if (x % 10 == 3) {
		System.out.print(" " + i);
		return;
	    }
	    x /= 10;
	}
    }
} Main public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.next());
	call(n);
    } main {
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.next());
	call(n);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = Integer.parseInt(scan.next()); n Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan call(n) call n String[] args args public static void call(int n) {
	for (int i = 1; i <= n; i++) {
	    if (i % 3 == 0) {
		System.out.print(" " + i);
		continue;
	    }
	    include3(i);
	}
	System.out.println();
    } call {
	for (int i = 1; i <= n; i++) {
	    if (i % 3 == 0) {
		System.out.print(" " + i);
		continue;
	    }
	    include3(i);
	}
	System.out.println();
    } for (int i = 1; i <= n; i++) {
	    if (i % 3 == 0) {
		System.out.print(" " + i);
		continue;
	    }
	    include3(i);
	} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
	    if (i % 3 == 0) {
		System.out.print(" " + i);
		continue;
	    }
	    include3(i);
	} {
	    if (i % 3 == 0) {
		System.out.print(" " + i);
		continue;
	    }
	    include3(i);
	} if (i % 3 == 0) {
		System.out.print(" " + i);
		continue;
	    } i % 3 == 0 i % 3 i 3 0 {
		System.out.print(" " + i);
		continue;
	    } System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i continue; include3(i) include3 i System.out.println() System.out.println System.out System System.out int n n public static void include3(int i) {
	int x = i;
	while (x > 0) {
	    if (x % 10 == 3) {
		System.out.print(" " + i);
		return;
	    }
	    x /= 10;
	}
    } include3 {
	int x = i;
	while (x > 0) {
	    if (x % 10 == 3) {
		System.out.print(" " + i);
		return;
	    }
	    x /= 10;
	}
    } int x = i; x i while (x > 0) {
	    if (x % 10 == 3) {
		System.out.print(" " + i);
		return;
	    }
	    x /= 10;
	} x > 0 x 0 {
	    if (x % 10 == 3) {
		System.out.print(" " + i);
		return;
	    }
	    x /= 10;
	} 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 int i i public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.next());
	call(n);
    }
    public static void call(int n) {
	for (int i = 1; i <= n; i++) {
	    if (i % 3 == 0) {
		System.out.print(" " + i);
		continue;
	    }
	    include3(i);
	}
	System.out.println();
    }
    public static void include3(int i) {
	int x = i;
	while (x > 0) {
	    if (x % 10 == 3) {
		System.out.print(" " + i);
		return;
	    }
	    x /= 10;
	}
    }
} public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.next());
	call(n);
    }
    public static void call(int n) {
	for (int i = 1; i <= n; i++) {
	    if (i % 3 == 0) {
		System.out.print(" " + i);
		continue;
	    }
	    include3(i);
	}
	System.out.println();
    }
    public static void include3(int i) {
	int x = i;
	while (x > 0) {
	    if (x % 10 == 3) {
		System.out.print(" " + i);
		return;
	    }
	    x /= 10;
	}
    }
} Main
import java.util.Scanner;
import java.lang.Math;
public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.next());
	call(n);
    }
    public static void call(int n) {
	for (int i = 1; i <= n; i++) {
	    if (i % 3 == 0) {
		System.out.print(" " + i);
		continue;
	    }
	    include3(i);
	}
	System.out.println();
    }
    public static void include3(int i) {
	int x = i;
	while (x > 0) {
	    if (x % 10 == 3) {
		System.out.print(" " + i);
		return;
	    }
	    x /= 10;
	}
    }
}