#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 17;
int n, p, frq[M], dp[(1 << M)];
char s[N];
bool can[M][M], okay[(1 << M)], cant[(1 << M)];
int solve(int mask) {
  if (!okay[mask]) return 1000000010;
  if (dp[mask] != -1) return dp[mask];
  dp[mask] = 0;
  for (int i = 0; i < p; i++) {
    if (((mask >> i) & 1) == 1) dp[mask] += frq[i];
  }
  for (int i = 0; i < p; i++) {
    if (((mask >> i) & 1) == 1) {
      dp[mask] = min(dp[mask], solve((mask ^ (1 << i))));
    }
  }
  return dp[mask];
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%d%d", &n, &p);
  scanf("%s", s);
  for (int i = 0; i < n; i++) {
    frq[s[i] - 'a']++;
  }
  for (int i = 0; i < p; i++) {
    for (int j = 0; j < p; j++) {
      scanf("%d", &can[i][j]);
    }
  }
  for (int i = 0; i < (1 << p); i++) okay[i] = true;
  bool A, B;
  int val = 0;
  for (int i = 0; i < p; i++) {
    for (int j = i; j < p; j++) {
      if (can[i][j]) continue;
      A = B = false;
      val = 0;
      for (int k = 0; k < (1 << p); k++) cant[k] = false;
      for (int k = 0; k < n; k++) {
        if (s[k] - 'a' == j && A == true) {
          cant[val] = true;
          val = 0;
        } else if (s[k] - 'a' == i && B == true) {
          cant[val] = true;
          val = 0;
        }
        if (s[k] - 'a' == i)
          B = false, A = true;
        else if (s[k] - 'a' == j)
          A = false, B = true;
        else if (A || B)
          val |= (1 << (s[k] - 'a'));
      }
      for (int k = 0; k < (1 << p); k++) {
        if (((k >> i) & 1) == 1 || ((k >> j) & 1) == 1) continue;
        for (int l = 0; l < p; l++) {
          if (((k >> l) & 1) == 1 && cant[k ^ (1 << l)]) {
            cant[k] = true;
            break;
          }
        }
      }
      for (int k = 0; k < (1 << p); k++) {
        if (((k >> i) & 1) == 0 || ((k >> j) & 1) == 0) continue;
        if (cant[k ^ ((1 << p) - 1)]) okay[k] = false;
      }
    }
  }
  cout << solve((1 << p) - 1) << endl;
  return 0;
}
