const x = Number(require('fs').readFileSync('/dev/stdin', 'utf8'));
let ans = [];
for (let i = 1; i < x + 1; i++) {
    if (i % 3 === 0) {
        ans.push(i);
        continue;
    }
     for (let x = i; x > 0; x = Math.floor(x /10)) {
            if ( x % 10 === 3 ) {
                ans.push(i);
                break;
           }
     }     
}
console.log(" " + ans.join(" "));
