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