H, W = map(int, input().split()) rows = H - (H % 2) cols = W - (W % 2) ans = rows * cols print(ans) for i in range(H): row = [] for j in range(W): if i < rows and j < cols: row.append('1') else: row.append('0') print(' '.join(row))