#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;
}
int N, P;
char str[111111];
int A[17][17];
bool ng[1 << 17];
int ei[1 << 17];
bool dp[1 << 17];
signed main() {
  scanf("%d%d", &N, &P);
  scanf("%s", str);
  for (int i = 0; i < (P); i++)
    for (int j = 0; j < (P); j++) scanf("%d", &A[i][j]);
  for (int x = 0; x < P; x++) {
    for (int y = x; y < P; y++) {
      if (A[x][y]) continue;
      memset(ei, 0, sizeof(ei));
      vector<int> lis;
      for (int i = 0; i < (N); i++)
        if (str[i] == 'a' + x || str[i] == 'a' + y) lis.push_back(i);
      for (int i = 0; i + 1 < lis.size(); i++) {
        int mask = 0;
        for (int j = lis[i] + 1; j < lis[i + 1]; j++)
          mask |= 1 << (str[j] - 'a');
        ei[mask] = 1;
      }
      for (int i = 0; i < (1 << P); i++) {
        for (int j = 0; j < (P); j++) {
          if (!(i >> j & 1)) continue;
          ei[i] |= ei[i ^ (1 << j)];
        }
      }
      for (int i = 0; i < (1 << P); i++)
        if (ei[i] && !(i >> x & 1) && !(i >> y & 1)) ng[i] = true;
    }
  }
  dp[0] = true;
  for (int i = 0; i < (1 << P); i++) {
    if (!dp[i]) continue;
    for (int j = 0; j < (P); j++) {
      if (i >> j & 1) continue;
      if (ng[i | (1 << j)]) continue;
      dp[i | (1 << j)] = true;
    }
  }
  vector<int> cnt(P);
  for (int i = 0; i < (N); i++) cnt[str[i] - 'a']++;
  int ans = N;
  for (int i = 0; i < (1 << P); i++) {
    if (!dp[i]) continue;
    int sum = 0;
    for (int j = 0; j < (P); j++)
      if (!(i >> j & 1)) sum += cnt[j];
    chmin(ans, sum);
  }
  cout << ans << endl;
  return 0;
}
