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

void main() {
    int n = getStdin!(int[])()[0];
    
    int flg = 1;
    int i = 1;
    int x;
    while(flg > 0) {
        // CHECK_NUM
        if (flg == 1) {
            x = i;
            if (x % 3 == 0) {
                " %d".writef(i);
                flg = 3;
                continue;
            }
            flg = 2;
            continue;
    	}

        // INCLUDE3
        if (flg == 2) {
            if (x % 10 == 3) {
                " %d".writef(i);
                flg = 3;
                continue;
            }
            x /= 10;
            if (x != 0) {
                flg = 2;
                continue;
            }

            flg = 3;
            continue;
        }

        // END_CHECK_NUM
        if (flg == 3) {
            if (++i <= n) {
                flg = 1;
                continue;
            }

            "".writeln;
            break;
        }
    }
}

T getStdin(T)() {
    string[] cmd;
    string line;
    while ((line = chomp(stdin.readln())) != "") cmd ~= line;
    return to!(T)(cmd);
}