def print_ans(): for l in ans: print(*l) return h,w = map(int,input().split()) ans = [[0 for _ in range(w)] for _ in range(h)] if h == 1 or w == 1: print(0) print_ans() elif h%2 == 0 and w%2 == 0: for i in range(h): for j in range(w): ans[i][j] = 1 print(h*w) print_ans() elif h%2 == 0 and w%2 == 1: for i in range(h): for j in range(w-1): ans[i][j] = 1 print(h*(w-1)) print_ans() elif h%2 == 1 and w%2 == 0: for i in range(h-1): for j in range(w): ans[i][j] = 1 print((h-1)*w) print_ans() else: for i in range(h-1): for j in range(w-1): ans[i][j] = 1 print((h-1)*(w-1)) print_ans()