#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005, MAXM = 140000;
int mp[20][20], ban[MAXM], f[MAXM], sum[20], cnt[20], n, m;
char str[MAXN];
vector<int> pre[MAXN], suf[MAXN];
void fwt(int *a, int n) {
  for (int h = 2; h <= n; h <<= 1) {
    int hh = h >> 1;
    for (int i = 0; i < n; i += h)
      for (int j = i; j < i + hh; j++) a[j + hh] += a[j];
  }
}
int main() {
  scanf("%d%d%s", &n, &m, str + 1);
  for (int i = 1; i <= n; i++) ++cnt[str[i] -= 'a'];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) scanf("%d", &mp[i][j]);
  memset(sum, -1, sizeof(sum));
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++)
      if (~sum[j] && !mp[str[i]][j] && !(sum[j] >> str[i] & 1)) {
        --ban[sum[j] | 1 << str[i]], --ban[sum[j] | 1 << j];
        ++ban[sum[j]], ++ban[sum[j] | 1 << str[i] | 1 << j];
      }
    sum[str[i]] = 0;
    for (int j = 0; j < m; j++)
      if (j != str[i]) sum[j] |= 1 << str[i];
  }
  memset(sum, -1, sizeof(sum));
  for (int i = n; i > 0; i--) {
    for (int j = 0; j < m; j++)
      if (~sum[j] && !mp[str[i]][j] && !(sum[j] >> str[i] & 1)) {
        --ban[sum[j] | 1 << str[i]], --ban[sum[j] | 1 << j];
        ++ban[sum[j]], ++ban[sum[j] | 1 << str[i] | 1 << j];
      }
    sum[str[i]] = 0;
    for (int j = 0; j < m; j++)
      if (j != str[i]) sum[j] |= 1 << str[i];
  }
  fwt(ban, 1 << m);
  f[0] = 1;
  int res = n;
  for (int i = 0; i < 1 << m; i++)
    if (f[i] && !ban[i]) {
      for (int j = 0; j < m; j++)
        if (~i >> j & 1) f[i | 1 << j] = 1;
      int now = n;
      for (int j = 0; j < m; j++)
        if (i >> j & 1) now -= cnt[j];
      res = min(res, now);
    }
  printf("%d\n", res);
  return 0;
}
