import sys import numpy as np def main(): n, k = map(int, input().split()) m = 0 for i in range(2 * n): m += input().count('#') C = np.fromstring(sys.stdin.read(), np.int64, sep=' ').reshape(-1, 2 * n) def f(A, x): if x == 0: return 0 return sum(np.sort(A.ravel())[-x:].tolist()) ans = f(C, m) if ~m & 1: ans = max(ans, f(C[:, :n] + np.fliplr(C[:, n:]), m // 2) + k) print(ans) if __name__ == '__main__': main()