H,W=map(int,input().split()) ANS=[[1]*W for i in range(H)] if H%2==0 and W%2==0: print(H*W) for ans in ANS: print(*ans) elif H%2==1 and W%2==0: print(H*W-W) for i in range(W): ANS[0][i]=0 for ans in ANS: print(*ans) elif H%2==0 and W%2==1: print(H*W-H) for i in range(H): ANS[i][0]=0 for ans in ANS: print(*ans) else: if H<=W: for i in range(W): ANS[min(i,H-1)][i]=0 print(H*W-W) else: for i in range(H): ANS[i][min(i,W-1)]=0 print(H*W-H) for ans in ANS: print(*ans)