N,K = map(int,input().split()) black_count = 0 for _ in range(2*N): black_count += input().count("#") li = [] li_sym = [] for i in range(2*N): C = list(map(int,input().split())) for j in range(N): a = C[j] b = C[-j-1] li.append(a) li.append(b) li_sym.append(a+b) li.sort(reverse=True) li_sym.sort(reverse=True) ans = sum(li[:black_count]) if black_count % 2 == 0: k = black_count // 2 ans = max(ans,sum(li_sym[:k])+K) print(ans)