#include <bits/stdc++.h>
const int N = 100000;
const int A = 17;
const int LG = 17;
int n, p, ans = ~(1 << 31), pos[A], in[A], next[N][LG];
char s[N + 1];
bool m[A][A], u[1 << A], mask[A][A][1 << A];
void test(int state, int amount) {
  u[state] = true;
  for (int i = 0; i < p; ++i)
    if (state ^ (state | (1 << i)))
      for (int j = 0; j < p; ++j)
        if (state ^ (state | (1 << j)))
          if (!m[i][j] && mask[i][j][state]) return;
  ans = std::min(ans, amount);
  for (int i = 0; i < p; ++i)
    if ((state ^ (state | 1 << i)) && !u[state | (1 << i)])
      test(state | (1 << i), amount - in[i]);
}
int main() {
  scanf("%d%d%s", &n, &p, s);
  for (int i = 0; i < p; ++i)
    for (int j = 0; j < p; ++j) {
      int v;
      scanf("%d", &v);
      m[i][j] = v;
    }
  for (int i = n - 1; i >= 0; --i) {
    ++in[s[i] - 'a'];
    next[i][0] = 1 << (s[i] - 'a');
    for (int j = 1; i + (1 << j) <= n; ++j)
      next[i][j] = next[i][j - 1] | next[i + (1 << (j - 1))][j - 1];
    for (int ch = 0; ch < p; ++ch)
      if (pos[ch]) {
        int cur = 0;
        int p = i + 1;
        for (int j = LG - 1; j >= 0; --j)
          if (p + (1 << j) <= pos[ch]) {
            cur |= next[p][j];
            p += (1 << j);
          }
        mask[s[i] - 'a'][ch][cur] = true;
        mask[ch][s[i] - 'a'][cur] = true;
      }
    pos[s[i] - 'a'] = i;
  }
  for (int i = 0; i < p; ++i)
    for (int j = 0; j < p; ++j)
      for (int k = 0; k < (1 << p); ++k)
        for (int l = 0; l < p && !mask[i][j][k]; ++l)
          if (mask[i][j][k & ~(1 << l)]) mask[i][j][k] = true;
  test(0, n);
  printf("%d\n", ans);
  return 0;
}
