N, K = map(int, input().split()) S = [] cnt = 0 for i in range(2 * N): L = list(input()) cnt += L.count("#") S.append(L) C = [] V = [] for i in range(2 * N): L = list(map(int, input().split())) C.append(L) V.extend(L) V.sort(reverse=True) ans = sum(V[:cnt]) if cnt % 2: print(ans) exit() P = [] for i in range(2 * N): for j in range(N): P.append(C[i][j] + C[i][2 * N - 1 - j]) P.sort(reverse=True) print(max(ans, sum(P[:cnt//2]) + K))