def main():
    from sys import stdin, setrecursionlimit
    # setrecursionlimit(1000000)
    input = stdin.readline
    def iinput(): return int(input())
    def sinput(): return input().rstrip()
    def i0input(): return int(input()) - 1
    def linput(): return list(input().split())
    def liinput(): return list(map(int, input().split()))
    def miinput(): return map(int, input().split())
    def li0input(): return list(map(lambda x: int(x) - 1, input().split()))
    def mi0input(): return map(lambda x: int(x) - 1, input().split())
    INF = 1000000000000000000
    MOD = 1000000007

    N, K = miinput()
    S = []
    ctr = 0
    for _ in [0] * (2*N):
        tmp = sinput()
        S.append(tmp)
        ctr += tmp.count('#')
    
    C = []
    D = []
    for _ in [0] * (2*N):
        c = liinput()
        for k in c:
            C.append(k)
        for k, l in zip(c[:N], c[N:][::-1]):
            D.append(k+l)
    
    C.sort(reverse=True)
    ans = sum(C[:ctr])
    if ctr % 2 == 0:
        D.sort(reverse=True)
        ans = max(ans, K + sum(D[:ctr//2]))
    
    print(ans)
    


main()