num = gets.to_i;

for i in 1..num do
	
	if i % 3 == 0 then
		
		print " " + i.to_s;
		
	else
		
		str = i.to_s;
		#pos = str.index("3");
		#str.include?("l")
		if str.include?("3") then
			
			print " " + i.to_s;
			
		end
		
	end
	
end


print "\r\n"