n = gets.chomp.to_i
$i = 1
x = $i

def x(x)
	if (x % 3 == 0)
		print " " + $i.to_s
	end
	
	if(x % 10 == 3)
		print " " + $i.to_s
		return
	end
	
	x /= 10
	if (x) 
		if(x % 10 == 3)
			print " " + $i.to_s
			return
		end
	end
end

x(x)
$i += 1
while ( $i <= n) do
	x = $i
	x(x)
	$i += 1
	 "$i = " + $i.to_s
end