main(require("fs").readFileSync("/dev/stdin", "utf8").replace(/\r?\n$/, "").split(/\r?\n/));

function main(lines){
	var n = +lines, output = "";
	for(var i=1;i<=n;i++) if(i % 3 == 0 || i.toString().indexOf("3") >= 0){
		output += " " + i;
	}
	console.log(output);
}