
    Given a matrix of delivery route metrics where each row represents a unique route's performance indicators (traffic density, weather risk, fuel usage, and time estimates), rearrange the routes in ascending order based on their total complexity scores to optimize the delivery sequence. Each row's sum represents the route's overall risk and complexity factor, which must be used as the sorting criterion to determine the final route execution order.
    

    
def sort_matrix(M):
    """
    Given a matrix of delivery route metrics where each row represents a unique route's performance indicators (traffic density, weather risk, fuel usage, and time estimates), rearrange the routes in ascending order based on their total complexity scores to optimize the delivery sequence. Each row's sum represents the route's overall risk and complexity factor, which must be used as the sorting criterion to determine the final route execution order.
    

    """
def sort_matrix(M):
    """
    Given a matrix of delivery route metrics where each row represents a unique route's performance indicators (traffic density, weather risk, fuel usage, and time estimates), rearrange the routes in ascending order based on their total complexity scores to optimize the delivery sequence. Each row's sum represents the route's overall risk and complexity factor, which must be used as the sorting criterion to determine the final route execution order.
    

    """
    result = sorted(M, key=sum)
    return result