import io


def read_type_four_packet(buffer: io.StringIO) -> int:
    """
    Reads type 4 packet and returns the literal value inside the packet groups
    """
    buffer.read(3)  # version
    buffer.read(3)  # type
    value = ''

    while True:
        group = buffer.read(5)
        value += group[1:]

        if group.startswith('0'):
            break

    return int(value, 2)