N, K = map(int, input().split()) q, r = divmod(N, K * K) M = -K * (-N // (K * K)) G = [["." for _ in range(M)] for _ in range(M)] if q == 0: count = 0 for i in range(M): for j in range(M): if count >= N: break G[i][j] = "#" count += 1 else: for i in range(0, M - r, K): j = i for di in range(K): for dj in range(K): if 0 <= i + di < M and 0 <= j + dj < M: G[i + di][j + dj] = "#" count = 0 for i in range(K): for j in range(K): if count >= r: break G[K * q + i][K * q + j] = "#" count += 1 print(M) for g in G: print("".join(g))