#include <bits/stdc++.h>   using namespace std;   const int N = 500023;   bool vis[N];   vector<int> adj[N];   void solve() {     long long int n, m;     cin >> n >> m;     map<long long int, long long int> cntA;     map<long long int, long long int> cntB;     map<long long int, long long int> cntC;     map<long long int, long long int> cntD;     map<long long int, long long int> cntE;     for (long long int i = 0; i < n; i++) {       string s;       cin >> s;       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  A )           cntA[i]++;         else if (s[i] ==  B )           cntB[i]++;         else if (s[i] ==  C )           cntC[i]++;         else if (s[i] ==  D )           cntD[i]++;         else if (s[i] ==  E )           cntE[i]++;       }     }     long long int ans = 0;     for (int i = 0; i < m; i++) {       long long int c;       cin >> c;       long long int maxi = 0;       maxi = max(max(cntA[i], cntB[i]), cntC[i]);       maxi = max(max(maxi, cntD[i]), cntE[i]);       long long int temp = maxi * c;       ans += temp;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T = 1;     int t = 0;     while (t++ < T) {       solve();     }   }   