def zeta_to_small(N,A): res = [a for a in A] for i in range(N): t = 2**i for j in range(1<>j & 1: tmp = zeta_box[done] - zeta_box[done + 2**j] dp[S] = max(dp[S],dp[S-2**j]+tmp*tmp) return dp[-1] import sys input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) N,M = map(int,input().split()) V = list(map(int,input().split())) S = [input() for i in range(N)] print(solve(N,M,V,S))