#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int n, m, mx, ans = inf;
char s[N];
int a[N], tmp[1 << 17], f[1 << 17];
int cst[1 << 17], dp[1 << 17];
int g[17][17];
void dfs(int x) {
  if (tmp[x]) return;
  tmp[x] = 1;
  for (int y = x; y; y ^= y & -y) dfs(x ^ y & -y);
}
void dfs1(int x) {
  if (f[x] || tmp[x]) return;
  tmp[x] = 1;
  ans = min(ans, cst[x]);
  for (int y = x; y; y ^= y & -y) dfs1(x ^ y & -y);
}
int main() {
  scanf("%d%d%s", &n, &m, s + 1);
  mx = (1 << m) - 1;
  for (int i = 1; i <= n; i++) cst[1 << (a[i] = s[i] - 'a')]++;
  for (int i = 1; i <= mx; i++) cst[i] = cst[i ^ i & -i] + cst[i & -i];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) scanf("%d", &g[i][j]);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++)
      if (!g[i][j]) {
        int now = 0, pre = -1;
        for (int k = 1; k <= n; k++) {
          if (a[k] == i || a[k] == j) {
            if (a[k] == i && pre == j || a[k] == j && pre == i) dfs(mx ^ now);
            now = 0, pre = a[k];
          } else
            now |= 1 << a[k];
        }
        int t = 1 << i | 1 << j;
        for (int k = 0; k <= mx; k++) {
          if ((k & t) == t) f[k] |= tmp[k];
          tmp[k] = 0;
        }
      }
  dfs1(mx);
  printf("%d\n", ans);
}
