#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, N = 1e6 + 10;
int n, p, P, ans = INF, a[N], tmp[1 << 17], f[1 << 17], ln[1 << 17], g[17][17];
char s[N];
void dfs0(int x) {
  if (tmp[x]) return;
  tmp[x] = 1;
  for (int y = x; y; y ^= y & -y) dfs0(x ^ y & -y);
}
void dfs1(int x) {
  if (f[x] || tmp[x]) return;
  tmp[x] = 1;
  ans = min(ans, ln[x]);
  for (int y = x; y; y ^= y & -y) dfs1(x ^ y & -y);
}
int main() {
  scanf("%d%d%s", &n, &p, s + 1);
  P = (1 << p) - 1;
  for (int i = 1; i <= n; i++) ++ln[1 << (a[i] = s[i] - 'a')];
  for (int i = 1; i <= P; i++) ln[i] = ln[i ^ i & -i] + ln[i & -i];
  for (int i = 0; i < p; i++)
    for (int j = 0; j < p; j++) scanf("%d", &g[i][j]);
  for (int i = 0; i < p; i++)
    for (int j = 0; j < p; 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) dfs0(P ^ now);
            now = 0, pre = a[k];
          } else
            now |= 1 << a[k];
        }
        int t = 1 << i | 1 << j;
        for (int k = 0; k <= P; k++) {
          if ((k & t) == t) f[k] |= tmp[k];
          tmp[k] = 0;
        }
      }
  dfs1(P);
  printf("%d\n", ans);
  return 0;
}
