H, W = map(int, input().split()) # Calculate the maximum number of black cells max_rows = H - (H % 2) max_cols = W - (W % 2) ans = max_rows * max_cols # Generate the grid grid = [] for i in range(H): row = [] for j in range(W): if i < max_rows and j < max_cols: row.append(1) else: row.append(0) grid.append(row) # Output the result print(ans) for row in grid: print(' '.join(map(str, row)))