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