var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var n = parseInt(input);
var result = [];
for (var i=1;i<=n;i++){
    if(i % 3 === 0){
        result.push(i);
    }
    if(i % 3 !== 0 && (i+"").match(/3/)){
      result.push(i);
    }
}
console.log(' ' + result.join(" "));
