"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});
/* 入力は 
 */

var re = /\s+|$/;
reader.on('close', () => {
    var l = lines[0].trim().split(re).map(Number);
    var n = l[0];
    
    aux(n);
});

function aux(n)
{
  var s='';
  for (var i=1; i<=n; i++){
    var x = i;
    if ( x % 3 == 0 ){
      s += " " + i.toString();
    } else {
      while (x > 0) {
	if ( x % 10 == 3 ){
	  s += " " + i.toString();
	  break;
	}
	x = Math.floor(x/10);
      }
    }

  }
  console.log(s);
}
