import std.stdio, std.string, std.conv, std.algorithm;

void main() {
    int n = readln.chomp.to!int;
    foreach (i; 1 .. n+1) {
        if (i % 3 == 0 || i.to!string.canFind("3")) write(" ", i);
    }
    writeln;
}
