H, W = map(int, input().split()) if H % 2 == W % 2 == 0: ans = [[1]*W for _ in range(H)] elif H*W % 2 == 0: if H % 2: ans = [[1]*W for _ in range(H-1)] ans.append([0]*W) else: ans = [[1]*(W-1)+[0] for _ in range(H)] else: ans = [[1]*W for _ in range(H)] if H > W: for i in range(H): ans[i][min(i, W-1)] = 0 else: for i in range(W): ans[min(i, H-1)][i] = 0 print(sum(sum(a) for a in ans)) for a in ans: print(*a)