const call = function (n) {
    var out = '';
    for (var i = 1; i <= n; i++) {
        if (i % 3 === 0 ) {
            out += ' ' + i;
            continue;
        }
        for (var x = i; x > 0; x = Math.floor(x /10)) {
            if ( x % 10 === 3 ) {
                out += ' ' + i;
                break;
            }
        }
    }
    console.log(out);
};

const chunk = require('fs').readFileSync('/dev/stdin', 'utf8');
call(Number(chunk));