#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, i, j, ii, jj, zx, xc, k[29][29], f[100009], g[100009], z, x,
    pas, A, B, ka[109];
bool p[19][19][133002];
bool dp[133002];
string s;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> a >> b;
  cin >> s;
  s.insert(0, "0");
  for (i = 1; i <= a; i++) f[i] = s[i] - 'a' + 1;
  for (i = 1; i <= a; i++) ka[f[i]]++;
  for (i = 1; i <= b; i++) {
    for (j = 1; j <= b; j++) {
      cin >> k[i][j];
    }
  }
  pas = a;
  for (A = 1; A <= b; A++) {
    for (B = 1; B <= b; B++) {
      if (k[A][B] == 1) continue;
      c = A;
      d = B;
      z = -1;
      for (i = a; i >= 1; i--) {
        if (f[i] != c && f[i] != d) continue;
        if (f[i] == c) {
          swap(c, d);
          z = i;
          break;
        } else {
          z = i;
          break;
        }
      }
      if (z == -1) continue;
      zx = (1 << b) - 1;
      zx ^= ((1 << (A - 1)) | (1 << (B - 1)));
      for (i = z - 1; i >= 1; i--) {
        if (f[i] != c && f[i] != d) {
          zx ^= (zx & (1 << (f[i] - 1)));
        } else {
          if (f[i] == c) {
            p[A][B][zx] = 1;
            swap(c, d);
            zx = (1 << b) - 1;
            zx ^= ((1 << (A - 1)) | (1 << (B - 1)));
          }
        }
      }
      for (i = (1 << b) - 1; i >= 0; i--) {
        if (p[A][B][i] != 0) {
          for (j = 0; j < b; j++) {
            if (j != A - 1 && j != B - 1 && ((1 << j) & i) != 0)
              p[A][B][(i ^ (1 << j))] = 1;
          }
        }
      }
    }
  }
  dp[(1 << b) - 1] = 1;
  pas = a;
  for (i = (1 << b) - 2; i >= 0; i--) {
    int ma = 0;
    for (j = 0; j < b; j++) {
      if (((1 << j) & i) != 0) ma += ka[j + 1];
    }
    for (j = 0; j < b; j++) {
      if (((1 << j) & i) == 0) {
        if (dp[(i ^ (1 << j))] == 1) {
          dp[i] = 1;
          break;
        }
      }
    }
    if (dp[i] == 0) continue;
    for (j = 0; j < b; j++) {
      for (jj = j; jj < b; jj++) {
        if ((i & (1 << j)) != 0 && (i & (1 << jj)) != 0) {
          if (p[j + 1][jj + 1][(i ^ ((1 << j) | (1 << jj)))] == 1) {
            dp[i] = 0;
            break;
          }
        }
      }
    }
    if (dp[i] == 1) {
      pas = min(pas, ma);
    }
  }
  cout << pas;
  return 0;
}
