#include <bits/stdc++.h>
using namespace std;
const int maxn = 17;
const long long ooi = 1e9 + 7;
const long long mod = 1e9 + 7;
int dp[1 << maxn];
string s;
int mat[maxn][maxn];
int n, p;
set<int> forbid;
int cnt[maxn];
int can[1 << maxn];
void del(char a, char b) {
  int p1 = 0;
  int p2 = 0;
  int i = a - 'a';
  int j = b - 'a';
  vector<vector<int> > no;
  int ts = 0;
  while (p1 < n) {
    while (p1 < n && s[p1] != a && s[p1] != b) p1++;
    if (p1 == n) break;
    p2 = p1 + 1;
    if (s[p1] == a)
      while (p2 < n && s[p2] != b) p2++;
    else if (s[p1] == b)
      while (p2 < n && s[p2] != a) p2++;
    if (p2 == n) break;
    int ts = (1 << p) - 1;
    ts ^= (1 << i);
    ts ^= (1 << j);
    for (int k = (p1 + 1); k < (p2); ++k) {
      int now = s[k] - 'a';
      if ((ts >> now) & 1) ts ^= (1 << now);
    }
    int yu1;
    for (yu1 = ts; yu1; yu1 = ts & (yu1 - 1))
      can[yu1 | (1 << i) | (1 << j)] = 0;
    can[yu1 | (1 << i) | (1 << j)] = 0;
    p1++;
    p2 = p1;
  }
}
void init() {
  cin >> n >> p;
  cin >> s;
  fill(can, can + (1 << p), 1);
  fill(dp, dp + (1 << p), -1);
  for (auto x : s) cnt[x - 'a']++;
  for (int i = (0); i < (p); ++i)
    for (int j = (0); j < (p); ++j) cin >> mat[i][j];
  for (int i = (0); i < (p); ++i)
    for (int j = (i); j < (p); ++j)
      if (!mat[i][j]) del(i + 'a', j + 'a');
}
int dfs(int nows) {
  if (~dp[nows]) return dp[nows];
  int ts = nows;
  int& ans = dp[nows];
  ans = 0;
  int t = 0;
  while (ts) {
    if (ts & 1)
      if (can[nows ^ (1 << t)]) ans = max(ans, dfs(nows ^ (1 << t)) + cnt[t]);
    ts >>= 1;
    t++;
  }
  return ans;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  cout << n - dfs((1 << p) - 1) << endl;
  return 0;
}
