a = gets.to_i
i = 3
while i <= a do
  if (i%3 == 0)
    print " #{i}"
  else
  j = i
    while j != 0
      if (j%10 == 3)
        print " #{i}"
        break
      else 
        j /=10  
      end
     
    end

  end
  i=i+1

end
puts ""
  
