def calc_num_terminal_mismatches(matches):
    """(Internal) Count the number of -1 entries at the end of a list of numbers.

    These -1 correspond to mismatches in the sequence to sequence search.
    """
    if matches[-1] != -1:
        return 0
    neg_len = -1
    while matches[neg_len] == -1:
        neg_len -= 1
    return abs(neg_len+1)