h,w = map(int,input().split()) ans = [[0]*w for i in range(h)] if h == 1 or w == 1: print(0) for i in ans: print(*i) exit() for i in range(0,h,2): for j in range(0,w,2): if i+1 < h and j+1 < w: ans[i][j] = ans[i+1][j] = ans[i][j+1] = ans[i+1][j+1] = 1 num = 0 for i in range(2): for j in range(2): num += ans[-1-i][-1-j] if num == 1: for i in range(2): for j in range(2): ans[-1-i][-1-j] ^= 1 num = 0 for i in ans: num += sum(i) print(num) for i in ans: print(*i)