#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
long long N, P;
char str[111111];
long long A[17][17];
bool ng[1 << 17];
long long ei[1 << 17];
bool dp[1 << 17];
signed main() {
  scanf("%lld%lld", &N, &P);
  scanf("%s", str);
  for (long long i = 0; i < (P); i++)
    for (long long j = 0; j < (P); j++) scanf("%lld", &A[i][j]);
  for (long long x = 0; x < P; x++) {
    for (long long y = x; y < P; y++) {
      if (A[x][y]) continue;
      memset(ei, 0, sizeof(ei));
      long long cur = 0;
      while (cur < N) {
        if (str[cur] != 'a' + x && str[cur] != 'a' + y) {
          cur++;
          continue;
        }
        long long mask = 0;
        long long nex = cur + 1;
        while (nex < N && str[nex] != 'a' + x && str[nex] != 'a' + y) {
          mask |= 1 << (str[nex] - 'a');
          nex++;
        }
        if (nex == N) break;
        cur = nex;
        ei[mask] = 1;
      }
      for (long long i = 0; i < P; i++) {
        for (long long j = 0; j < (1 << P); j++) {
          if (j & 1 << i) ei[j] += ei[j ^ 1 << i];
        }
      }
      for (long long i = 0; i < (1 << P); i++)
        if (ei[i] && !(i >> x & 1) && !(i >> y & 1)) ng[i] = true;
    }
  }
  dp[0] = true;
  for (long long i = 0; i < (1 << P); i++) {
    if (!dp[i]) continue;
    for (long long j = 0; j < (P); j++) {
      if (i >> j & 1) continue;
      if (ng[i | (1 << j)]) continue;
      dp[i | (1 << j)] = true;
    }
  }
  vector<long long> cnt(P);
  for (long long i = 0; i < (N); i++) cnt[str[i] - 'a']++;
  long long ans = N;
  for (long long i = 0; i < (1 << P); i++) {
    if (!dp[i]) continue;
    long long sum = 0;
    for (long long j = 0; j < (P); j++)
      if (!(i >> j & 1)) sum += cnt[j];
    chmin(ans, sum);
  }
  cout << ans << endl;
  return 0;
}
