var std = process.stdin;
std.resume();
std.setEncoding('utf8');

std.on('data', function(chunk){
    var n = +chunk.replace(/\n/, '');
    console.log(call(n));
});

var call = function(n){
    var output = '';
    
    for (var i = 3; i <= n; i++){
        if (i % 3 === 0) {
            output += ' ' + i;
        }
        else if (i % 3 !== 0 && (i+'').match(/3/)) {
            output += ' ' + i;
        }
    }
    
    return output;
};