H,W = map(int,input().split()) if H % 2 == 0 and W % 2 == 0: print(H*W) l = [1 for i in range(W)] for i in range(H): print(*l) elif H % 2 == 0: print(H*W-H) l = [1 for i in range(W)] l[-1] = 0 for i in range(H): print(*l) elif W % 2 == 0: print(H*W-W) l = [1 for i in range(W)] for i in range(H-1): print(*l) l = [0 for i in range(W)] print(*l) else: if min(H,W) == 1: print(0) l = [0 for i in range(W)] for i in range(H): print(*l) else: L = [[1 for i in range(W)]for j in range(H)] for i in range(H): for j in range(W): if i == H-1 or j == W-1: L[i][j] = 0 L[-1][-1] = 1 L[-1][-2] = 1 L[-2][-1] = 1 L[-2][-2] = 0 ans = 0 for i in range(H): ans += sum(L[i]) print(ans) for i in range(H): print(*L[i])