Orlp gives a solution using O(n) words of space, which are O(nlogn) bits of space (assuming for simplicity that n=m). Conversely, it is easy to show that Ω(n) bits of space are needed by reducing set disjointness to your problem.
Suppose that Alice holds a binary vector x1,…,xn and Bob holds a binary vector y1,…,yn, and they want to know whether there exists an index i such that xi=yi=1. They run your algorithm for the 2×(2n−1) matrix whose rows are x1,0,x2,0,…,0,xn and y1,0,y2,0,…,0,yn. After the first row is read, Alice sends Bob ∑ixi as well as the memory contents, so that Bob can complete the algorithm and compare ∑i(xi+yi) to the number of connected components. If the two numbers match, the two vectors are disjoint (there is no index i), and vice versa. Since any protocol for set disjointness needs Ω(n) bits (even if it can err with a small constant probability), we deduce an Ω(n) lower bound, which holds even for randomized protocols which are allowed to err with some small constant probability.
We can improve on Orlp's solution by using noncrossing partitions. We read the matrix row by row. For each row, we remember which 1s are connected via paths going through preceding rows. The corresponding partition is noncrossing, and so can be encoded using O(n) bits (since noncrossing partitions are counted by Catalan numbers, whose growth rate is exponential rather than factorial). When reading the following row, we maintain this representing, and increase a counter whenever all ends of some part are not connected to the current row (the counter takes an additional O(logn) bits). As in Orlp's solution, we add a final dummy row of zeroes to finish processing the matrix. This solution uses O(n) bits, which is asymptotically optimal given our lower bound.