var input = require('fs').readFileSync('/dev/stdin', 'utf8');

var n = Number(input);

var result = [];

for (var i = 1; i <= n; i++) {
    if (i % 3 === 0 ){
        result.push(i);
        continue;
    }

    var x = i;
    while(x) {
        if (x % 10 === 3) {
            result.push(i);
            break;
        }
        x = Math.floor( x / 10);
    }
}
    console.log(" " + result.join(" "));



