#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9,
                  Gold = ((1 + sqrt(5)) / 2);
long long keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
long long keyCount = sizeof(keymod) / sizeof(long long);
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcountll(s);
}
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
string cppstr_infile = "FILE.IN";
string cppstr_outfile = "FILE.OUT";
int n, p;
string s;
vector<vector<int> > A;
vector<int> val;
vector<vector<int> > PrefixSum;
vector<vector<int> > charList;
bool vis[17][17][131072], allowed[131072];
int RangeSum(int id, int L, int R) {
  int sum = PrefixSum[id][R];
  if (L > 0) sum -= PrefixSum[id][L - 1];
  return sum;
}
int DFS(int z, vector<bool>& checked) {
  int res = val[z];
  checked[z] = true;
  for (int i = 0; i < p; i++) {
    if (getbit(z, i)) continue;
    int newmask = z | (1 << i);
    if (!allowed[newmask]) continue;
    if (checked[newmask]) continue;
    res = min(res, DFS(newmask, checked));
  }
  return res;
}
void Spray(int z, int x, int y) {
  vis[x][y][z] = true;
  vis[y][x][z] = true;
  allowed[z] = false;
  for (int i = 0; i < p; i++) {
    if (i == x || i == y) continue;
    if (getbit(z, i)) continue;
    int newmask = z | (1 << i);
    if (vis[x][y][newmask]) continue;
    Spray(newmask, x, y);
  }
}
void Input() {
  for (int i = 0; i < 131072; i++) allowed[i] = true;
  cin >> n >> p >> s;
  A.resize(p, vector<int>(p));
  val.resize(1 << p, n);
  PrefixSum.resize(p, vector<int>(n, 0));
  charList.resize(p);
  for (int i = 0; i < p; i++) {
    for (int j = 0; j < p; j++) {
      cin >> A[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    int id = s[i] - 'a';
    charList[id].push_back(i);
    PrefixSum[id][i]++;
  }
  for (int i = 0; i < p; i++) {
    for (int j = 1; j < n; j++) {
      PrefixSum[i][j] += PrefixSum[i][j - 1];
    }
  }
}
void Solve() {
  for (int mask = 0; mask < (1 << p); mask++) {
    for (int i = 0; i < p; i++) {
      if (!getbit(mask, i)) continue;
      val[mask] -= charList[i].size();
    }
  }
  for (int i = 0; i < p; i++) {
    for (int j = 0; j < p; j++) {
      if (A[i][j]) continue;
      int ptr1 = 0, ptr2 = 0;
      while (ptr1 < charList[i].size()) {
        while (ptr2 < charList[j].size() &&
               charList[i][ptr1] >= charList[j][ptr2])
          ptr2++;
        if (ptr2 == charList[j].size()) break;
        while (ptr1 + 1 < charList[i].size() &&
               charList[i][ptr1 + 1] < charList[j][ptr2])
          ptr1++;
        if (ptr1 == charList[i].size()) break;
        int L = charList[i][ptr1], R = charList[j][ptr2];
        if (L + 1 >= R) {
          ptr1++;
          continue;
        }
        int mask = 0;
        for (int x = 0; x < p; x++) {
          if (RangeSum(x, L + 1, R - 1) == 0) continue;
          mask |= (1 << x);
        }
        allowed[mask] = false;
        ptr1++;
        if (!vis[i][j][mask]) Spray(mask, i, j);
      }
    }
  }
  vector<bool> checked(1 << p, false);
  cout << DFS(0, checked) << '\n';
}
int main(int argc, char* argv[]) {
  ControlIO(argc, argv);
  Input();
  TimerStart();
  Solve();
  TimerStop();
  return 0;
}
void ControlIO(int argc, char* argv[]) {
  char* infile = new char[cppstr_infile.size() + 1];
  char* outfile = new char[cppstr_outfile.size() + 1];
  strcpy(infile, cppstr_infile.c_str());
  strcpy(outfile, cppstr_outfile.c_str());
}
void TimerStart() {}
void TimerStop() {}
void Exit() {
  TimerStop();
  exit(0);
}
