H, W = map(int, input().split()) G = [[0] * W for _ in range(H)] if H == 1 or W == 1: ans = 0 elif H % 2 == 0 and W % 2 == 0: G = [[1] * W for _ in range(H)] elif H % 2 == 0: for i in range(H): for j in range(W-1): G[i][j] = 1 elif W % 2 == 0: for i in range(H-1): for j in range(W): G[i][j] = 1 else: for i in range(H-1): for j in range(W-1): G[i][j] = 1 G[-1][-1] = 1 G[-2][-1] = 1 G[-1][-2] = 1 G[-2][-2] = 0 ans = sum(sum(d) for d in G) print(ans) for g in G: print(*g)