const input = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n').map(Number);
console.log(function(i, n) {
  return i <= n ? ((i % 3 == 0 || include3(i)) ? ' ' + i : '') + arguments.callee(i + 1, n) : '';
}(1, input[0]));

function include3(i) {
  if (i == 0) return false;
  return i % 10 == 3 ? true : include3(Math.floor(i / 10));
}