N, K = map(int, input().split()) if N == K * (K + 1): print(K + 1) for i in range(K+1): for j in range(K+1): if i == j: print(".", end="") else: print("#", end="") print() exit() d, m = divmod(N, K * K) r = 0 while True: if r * r >= m: break r += 1 size = K * d + r res = [[0] * size for _ in range(size)] p = 0 for _ in range(d): for i in range(K): for j in range(K): res[p + i][p + j] = N N = max(0, N-1) p += K for i in range(r): for j in range(r): res[p + i][p + j] = N N = max(0, N-1) print(size) for r in res: for i in r: if i: print("#", end="") else: print(".", end="") print()