n, m = map(int, input().split()) if n == 1 or m == 1: ans = [[0] * m for _ in range(n)] print(0) for row in ans: print(*row) exit(0) x = n // 2 * 2 y = m // 2 * 2 print(x * y) ans = [[0] * m for _ in range(n)] for i in range(x): for j in range(y): ans[i][j] = 1 for row in ans: print(*row)