n = gets.chomp.to_i
i = 1
loop do
  x = i
  if x % 3 == 0
    print " #{i}"
    i += 1
    if i <= n
      next
    else
      break
    end
  end

  loop do
    if x % 10 == 3
      print " #{i}"
      if i <= n
        break
      else
        puts
        return
      end
    end
    x /= 10
    break if x == 0
  end

  i += 1
  if i > n
    break
  end
end
puts

