def include3?(x)
	return (x % 10 == 3)
end


n = gets.to_i
cout = ""
for i in 1..n
	x = i
	if(x%3 == 0)
		print(cout + " " + i.to_s)
		next
	end

	while x != 0
	  if(include3?(x))
		  print(cout + " " + i.to_s)
		  x = 0
	  else
	  	x /= 10
	  end
	end
end
puts cout