def reduce_bottom_rows(m, qubits):
    """Using just row_add's from the first qubit rows in m, tries to find a row that can be 
    completely zero'd out. Returns the rownumber of this row when successful."""
    cols = m.cols()
    leading_one = {}
    adds = []
    for r in range(qubits):
        while True:
            i = next(i for i in range(cols) if m.data[r][i])
            if i in leading_one:
                m.row_add(leading_one[i], r)
                adds.append((leading_one[i], r))
            else:
                leading_one[i] = r
                break
    for r in range(qubits, m.rows()):
        while True:
            if not any(m.data[r]):
                return r
            i = next(i for i in range(cols) if m.data[r][i])
            if i not in leading_one:
                break
            m.row_add(leading_one[i], r)
            adds.append((leading_one[i], r))
    raise ValueError('Did not find any completely reducable row')
