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 ans = [[0] * m for _ in range(n)] for i in range(x): for j in range(y): ans[i][j] = 1 if n % 2 == 1 and m % 2 == 1: print(x * y + 2) ans[-1][-1] = 1 ans[-1][-2] = 1 ans[-2][-1] = 1 ans[-2][-2] = 0 else: print(x * y) for row in ans: print(*row)