'use strict';
(function(stdin) {
	var lines  = stdin.toString().split('\n');
	var result = (function(data) {
		return new Range(1,data)
		.filter(function(v) {
			return ((v % 3 === 0) || contain_three(v));
	}).join(' ');
	
	function contain_three(num) {
		var digit = num;
		while (digit > 0) {
			if (digit % 10 === 3) return true;
			digit = ~~(digit / 10);
		}
		return false;
	}

	function Range(begin,end) { 
		var result = [];
		for (var i = begin; i <= end; i++) result.push(i);
			return result;
	}
}(parseInt(lines[0],10)
	));
console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));