function main(input) {
  var temp = parseInt(input);
  var answer = "";
  for (var i = 1; i < temp+1; i++) {

    if (i%3 == 0 || i.toString().includes("3")) {
      answer += (" "+i);
    }
  }
  console.log(answer);
}

var x = require('fs').readFileSync('/dev/stdin', 'utf-8');
main(x);
