def count_disordered(arr, size):
    """Counts the number of items that are out of the expected
    order (monotonous increase) in the given list."""

    counter = 0

    state = {
        "expected": next(item for item in range(size) if item in arr),
        "checked": []
    }

    def advance_state():
        state["expected"] += 1

        while True:
            in_arr = state["expected"] in arr
            is_overflow = state["expected"] > size
            not_checked = state["expected"] not in state["checked"]

            if not_checked and (in_arr or is_overflow):
                return

            state["expected"] += 1

    for val in arr:
        if val == state["expected"]:
            advance_state()
        else:
            counter += 1

        state["checked"].append(val)

    return counter