#include <bits/stdc++.h>
using namespace std;
char getc() {
  char c = getchar();
  while ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9'))
    c = getchar();
  return c;
}
int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return x * f;
}
int n, m, c[100010], b[100010], cnt[17], ans;
char s[100010];
bool a[17][17], f[1 << 17], g[1 << 17];
signed main() {
  n = read(), m = read();
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++) cnt[c[i] = s[i] - 'a']++;
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) {
      a[i][j] = read();
      if (i <= j && !a[i][j]) {
        memset(g, 0, sizeof(g));
        int last = -1, s = 0;
        for (int x = 1; x <= n; x++) {
          if (c[x] == i || c[x] == j) {
            if (last == i + j - c[x]) g[s] = 1;
            last = c[x];
            s = 0;
          } else
            s |= (1 << c[x]);
        }
        for (int x = 1; x < (1 << m); x++)
          if (!g[x] && !(x & (1 << i)) && !(x & (1 << j))) {
            for (int t = x, y = t & -t; t; t ^= y, y = t & -t) g[x] |= g[x ^ y];
          }
        for (int x = 0; x < (1 << m); x++) f[x] |= g[x];
      }
    }
  ans = n;
  for (int i = 1; i < (1 << m); i++) {
    if (!f[i]) {
      f[i] = 1;
      for (int j = 0; j < m; j++)
        if ((i & (1 << j)) && !f[i ^ (1 << j)]) {
          f[i] = 0;
          break;
        }
    }
    if (!f[i]) {
      int tot = n;
      for (int j = 0; j < m; j++)
        if (i & (1 << j)) tot -= cnt[j];
      ans = min(ans, tot);
    }
  }
  cout << ans;
  return 0;
}
