#include <bits/stdc++.h>
using namespace std;
string s;
int A[20][20];
int oc[20];
int n, p;
int getLen(int msk) {
  int ans = 0;
  for (int i = 0; i < p; i++) {
    if (msk & (1 << i)) ans += oc[i];
  }
  return ans;
}
int valid[1 << 17];
int bolod[1 << 17];
int solve(int msk) {
  if (bolod[msk] != -1) return bolod[msk];
  int ans = getLen(msk);
  for (int i = 0; i < p; i++) {
    if (msk & (1 << i)) {
      int newmask = msk ^ (1 << i);
      if (valid[newmask]) ans = min(ans, solve(newmask));
    }
  }
  return bolod[msk] = ans;
}
int last[20];
vector<bool> dp[17][17][18];
int maxmask;
void presos() {
  for (int i = 0; i < p; i++) {
    for (int j = i; j < p; j++) {
      for (int k = 1; k <= p; k++) {
        for (int msk = 0; msk < maxmask; msk++) {
          dp[i][j][k][msk] = dp[i][j][k - 1][msk];
          if (msk & (1 << (k - 1))) {
            dp[i][j][k][msk] =
                dp[i][j][k][msk] | dp[i][j][k - 1][msk ^ (1 << (k - 1))];
          }
        }
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(bolod, -1, sizeof bolod);
  cin >> n >> p >> s;
  for (char c : s) oc[c - 'a']++;
  maxmask = (1 << p) - 1;
  for (int i = 0; i < p; i++) {
    for (int j = 0; j < p; j++) {
      cin >> A[i][j];
    }
  }
  for (int i = 0; i < p; i++) {
    for (int j = 0; j < p; j++) {
      for (int k = 0; k <= p; k++) {
        dp[i][j][k].resize(maxmask);
      }
    }
  }
  for (int i = 0; i < p; i++) last[i] = -1;
  for (int k = 0; k < n; k++) {
    int i = s[k] - 'a';
    for (int j = 0; j < p; j++) {
      if (last[j] == -1) continue;
      if (A[i][j]) continue;
      int helper = 0;
      for (int l = 0; l < p; l++) {
        if (last[j] < last[l]) {
          helper |= (1 << l);
        }
      }
      dp[i][j][0][helper] = 1;
      dp[j][i][0][helper] = 1;
    }
    last[i] = k;
  }
  presos();
  valid[0] = 1;
  for (int newmask = 1; newmask <= maxmask; newmask++) {
    bool okay = true;
    for (int a = 0; a < p && okay; a++) {
      if ((newmask & (1 << a)) == 0) continue;
      for (int b = a; b < p && okay; b++) {
        if ((newmask & (1 << b)) == 0) continue;
        if (A[a][b]) continue;
        int rv = maxmask ^ newmask;
        if (dp[a][b][p][rv]) {
          okay = false;
          break;
        }
      }
    }
    valid[newmask] = okay;
  }
  cout << solve(maxmask) << "\n";
  return 0;
}
