public int findRankBinary(int[][] matrix) {
		int n = matrix.length;
		int m = matrix[0].length;
		// number of linearly independent row vector so far
		int row = 0;
		for (int i = 0; i < m; i++) {
			// for every column, scan the entire column
			int max = 0;
			int maxRow = 0;
			for (int j = row; j < n; j++) {
				if (max < matrix[j][i]) {
					max = matrix[j][i];
					maxRow = j;
					break; // because it's binary
				}
			}
			if (max == 0)
				continue;
			// swap such that matrix[row] is another linearly independent vector with
			// the ith entry non-zero
			int[] temp = matrix[maxRow];
			matrix[maxRow] = matrix[row];
			matrix[row] = temp;
			
			// subtract multiple of ith row so that all other rows have the ith entry 0
			// since its binary, the non-zero element is always 1
			for (int j = row + 1; j < n; j++) {
				if (matrix[j][i] != 0) {
					for (int k = i; k < m; k++) {
						matrix[j][k] = matrix[j][k] - matrix[row][k];
						// mod 2
						if (matrix[j][k] == -1)
							matrix[j][k] = 1;
					}
				}
			}
			row++;
			if (row == n)
				break;
		}
		// row = rank now
		return row;
	}