"use strict"
const input = require('fs').readFileSync('/dev/stdin','utf8');
const x = parseInt(input);

let ans = '';
for (let i = 1; i <= x; i++) {
	if (i % 3 === 0 || i % 10 === 3 || include3(i)) {
		ans += ' ' + i;
	}
}
console.log(ans);

function include3(x) {
	while (x > 0) {
		x = parseInt(x / 10);
		if (x % 10 === 3) return true;
	}
	return false;
}
