I=input
def J():
	return map(int,I().split())
N,K=J()
R=range(N*2)
b=0
for i in R:
	for c in I():b+=c=="#"
D,E=[],[]
for i in R:
	C=list(J())
	for i in R:
		D.append(C[i]),E.append(C[i]+C[N*2-i-1])
a=sum(sorted(D)[-b:])
if b%2:a=max(a,K+sum(sorted(E)[-b//2:]))
print(a)