#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7, INF = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
  long long r = 1 % P;
  for (a %= P; n; a = a * a % P, n >>= 1)
    if (n & 1) r = r * a % P;
  return r;
}
long long inv(long long first) {
  return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;
}
const int N = 1e6 + 10;
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 first) {
  if (tmp[first]) return;
  tmp[first] = 1;
  for (int second = first; second; second ^= second & -second)
    dfs(first ^ second & -second);
}
void dfs1(int first) {
  if (f[first]) return;
  ans = min(ans, cst[first]);
  for (int second = first; second; second ^= second & -second)
    dfs1(first ^ second & -second);
}
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 - 1; ++i)
    for (int j = 0; j <= m - 1; ++j) scanf("%d", &g[i][j]);
  for (int i = 0; i <= m - 1; ++i)
    for (int j = 0; j <= m - 1; ++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) f[k] |= tmp[k];
          tmp[k] = 0;
        }
      }
  dfs1(mx);
  printf("%d\n", ans);
}
