def compare_trace(trace, sol):
    """Compares TRACE with the SOLUTION trace, and returns the turn number
    where the two traces differ, or -1 if the traces are the same.
    """
    i = 0
    while i < min(len(trace), len(sol)):
        state, sol_state = trace[i], sol[i]
        if not state.is_correct(sol_state):
            return i
        i += 1
    if len(trace) != len(sol):
        return len(trace)
    return -1