#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000000 + 7;   const long long int N = 1000000 + 6;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int tc;     tc = 1;     while (tc--) {       long long int n, m;       cin >> n >> m;       string s[n];       for (long long int i = 0; i < n; i++) cin >> s[i];       long long int d[m];       for (long long int i = 0; i < m; i++) cin >> d[i];       long long int ans = 0;       for (long long int j = 0; j < m; j++) {         map<char, long long int> p;         long long int t = 0;         for (long long int i = 0; i < n; i++) {           p[s[i][j]]++;           t = max(t, p[s[i][j]]);         }         ans += t * d[j];       }       cout << ans;     }   }   