'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {

	var lines = chunk.toString().split('\n');
	var result = (function(number) {
		return Range(1,number)
		.filter(function(v) {
			return ((v % 3 === 0) 
				|| (function(num) {
					var digit = num;
					while (digit > 0) {
						if (digit % 10 === 3) return true;
						digit = ~~(digit / 10);
					}
					return false;
				}(v))); 
		}).join(' ');
	}(parseInt(lines[0],10)));

	console.log(result);

	function Range(begin,end) {
		var result = [];
		for (var i = begin; i <= end; i++) {
			result.push(i);
		}
		return result;
	}
});