n = gets.to_i
i = 1

while (i <= n)
  x = i
  if x % 3 == 0
    printf(" %d", i)
    i += 1
    next
  end
  while x > 0
    if x % 10 == 3
      printf(" %d", i)
      break
    end
    x /= 10
  end
  i += 1
end
printf "\n"

