def last_occurence_of_tag_chain(sequence, tag_type):
    """
    Takes a sequence of tags. Assuming the first N tags of the sequence are all of the type tag_type, it will return
    the index of the last such tag in that chain, i.e. N-1

    If the first element of the sequence is not of type tag_type, it will return -1
    """
    for i in range(0, len(sequence)):
        if sequence[i][1] != tag_type:
            return i - 1
    return len(sequence)