var input = require('fs').readFileSync('/dev/stdin', 'utf8');
const n = Number(input);
 let result = ' ';
 
 for (var i = 1; i <=n; i++) {
   if (i%3 === 0 ) {
     result += String(i)+' ';
   } else {
     if (String(i).match(/3/)) {
       result += String(i)+' ';
     }
   }
 }
 
 console.log(result.slice( 0, -1 ));
