#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 100001;
const int P = 17;
int n, p, a[P], dp[1 << P][P][P], fr[P], ln[1 << P], ans[1 << P];
bool bad[1 << P];
char tmp[N];
int calc(int msk) {
  int &ret = ans[msk];
  if (ret != -1) return ret;
  ret = ln[msk];
  for (int j = 0; j < p; ++j)
    if ((msk & (1 << j)) == 0 && !bad[msk ^ (1 << j)])
      ret = min(ret, calc(msk ^ (1 << j)));
  return ret;
}
int main() {
  memset(ans, -1, sizeof ans);
  scanf("%d%d%s", &n, &p, tmp);
  for (int i = 0; i < n; ++i) fr[tmp[i] - 'a']++;
  for (int msk = 0; msk < (1 << p); ++msk)
    for (int bt = 0; bt < p; ++bt)
      if ((msk & (1 << bt)) == 0) ln[msk] += fr[bt];
  for (int i = 0; i < p; ++i)
    for (int bt, j = 0; j < p; ++j) {
      scanf("%d", &bt);
      bt = (1 << j) * (bt);
      a[i] |= bt;
    }
  for (int i = 0; i < p; ++i)
    for (int j = 0; j < p; ++j) {
      if (((1 << j) & a[i]) > 0) continue;
      int idx = -1;
      for (int k = 0; k < n && idx == -1; ++k)
        if (tmp[k] - 'a' == i) idx = k;
      if (idx == -1) continue;
      for (int msk = 0, k = idx; k < n; ++k) {
        int cr = (1 << (tmp[k] - 'a'));
        msk |= cr;
        if (tmp[k] - 'a' == j && k != idx) {
          int fn = msk;
          if ((fn & (1 << i))) fn ^= (1 << i);
          if ((fn & (1 << j))) fn ^= (1 << j);
          dp[fn][i][j] = 1;
        }
        if (tmp[k] == (i + 'a')) msk = 0;
      }
    }
  for (int msk = 0; msk < (1 << p); ++msk)
    for (int i = 0; i < p; ++i)
      for (int j = 0; j < p; ++j) {
        for (int bt = 0; bt < p; ++bt) {
          if (bt == i || bt == j || (msk & (1 << bt)) > 0) continue;
          dp[msk ^ (1 << bt)][i][j] |= dp[msk][i][j];
        }
        bad[msk] |= dp[msk][i][j];
      }
  printf("%d\n", calc(0));
  return 0;
}
