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