Note that any 0 we encounter automatically knocks out of consideration the row and column at the intersection of which it is located. Therefore - we will catch not 1, we will catch 0.
Moving on the matrix. Only not by a frontal search, but by a snake:
1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7
Meeting 0, we must immediately memorize our coordinates in two arrays - "bad lines" and "bad columns", and then, finding ourselves on such lines and columns - skip them entirely. In addition, we should immediately jump forward to the wall from our previous turns, because this horizontal or vertical can be considered "bad."
Our matrix traveler, in addition to the coordinates, has a direction of movement - either horizontal or vertical. So, the pass must be done only then. when we go in the "horizontal mode" on a bad line and in the "vertical mode" on a bad column.
If our snake rested its forehead on the wall or in the previous round - hooray, we found the right column or row.
Extreme cases:
The matrix is crammed with 0 - we catch it at the first pass horizontally by filling in the black list of columns.
The matrix is crammed 1 - we catch it on the first pass, registering the whole line of 1
nxn? - Harry