n=gets.to_i
result=['']
i=1

while i <= n
  x=i
  if x%3==0
    result<<i
  else
    begin
      if x%10==3
        result<<i
        break
      end
      x /= 10
    end while(x>0)
  end
  i+=1
end

puts result*' '