#include <bits/stdc++.h>
int N, P, A[17][17];
char S[100001];
int bad[1 << 17];
int tmp[1 << 17];
int dp[1 << 17];
int F[17];
int main() {
  scanf("%d %d %s", &N, &P, S);
  for (int i = 0; i < N; i++) {
    S[i] -= 'a';
    F[S[i]]++;
  }
  for (int i = 0; i < P; i++) {
    for (int j = 0; j < P; j++) {
      scanf("%d", &A[i][j]);
    }
  }
  for (int i = 0; i < P; i++) {
    for (int j = 0; j < P; j++) {
      if (A[i][j]) continue;
      int k = 0;
      while (k < N && S[k] != i && S[k] != j) k++;
      while (k < N) {
        int l = k;
        k++;
        int m = 0;
        while (k < N && S[k] != i && S[k] != j) m |= 1 << S[k++];
        if (k != N && ((S[k] == i && S[l] == j) || (S[l] == i && S[k] == j))) {
          tmp[m] = 1;
        }
      }
      for (int k = 0; k < 1 << P; k++) {
        if (k >> i & 1) continue;
        if (k >> j & 1) continue;
        for (int l = 0; l < P; l++) {
          if (l == i) continue;
          if (l == j) continue;
          tmp[k | 1 << l] |= tmp[k];
        }
      }
      for (int k = 0; k < 1 << P; k++) {
        bad[k] |= tmp[k];
        tmp[k] = 0;
      }
    }
  }
  dp[0] = 1;
  for (int i = 0; i < 1 << P; i++) {
    for (int j = 0; j < P; j++) {
      if ((~i >> j & 1) && !bad[i | 1 << j]) {
        dp[i | 1 << j] |= dp[i];
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 1 << P; i++)
    if (dp[i]) {
      int s = 0;
      for (int j = 0; j < P; j++)
        if (i >> j & 1) s += F[j];
      if (ans < s) ans = s;
    }
  printf("%d\n", N - ans);
  return 0;
}
