import sys input = sys.stdin.readline H,W=map(int,input().split()) if 1 in [H,W]: print(0) exit() ans=[1]*W if H%2==0: if W%2==0: print(H*W) for i in range(H):print(*ans) else: print(H*W-H) ans[0]=0 for i in range(H): print(*ans) else: if W%2==0: print(H*W-W) print(*[0]*W) for i in range(H-1): print(*ans) else: if H>W: print(H*W-H) for i in range(W): ans[i-1]=1 ans[i]=0 print(*ans) for i in range(H-W): print(*ans) else: print(H*W-W) for i in range(H-1): ans[i-1]=1 ans[i]=0 print(*ans) ans = [1]*(H-1)+[0]*(W-H+1) print(*ans)