#include <bits/stdc++.h>
using namespace std;
char s[100001];
int n, m, A[17][17], a[100001], cnt[17];
bool dp[(1 << 17)], mark[17][17][(1 << 17)];
void Mark(int mask, int a, int b) {
  if (mark[a][b][mask]) {
    return;
  }
  dp[mask] = true;
  mark[a][b][mask] = true;
  for (int k = 0; k < m; ++k) {
    if ((mask & (1 << k)) == 0 || k == a || k == b) {
      continue;
    }
    Mark(mask ^ (1 << k), a, b);
  }
}
int main() {
  scanf("%d%d%s", &n, &m, s);
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &A[i][j]);
    }
  }
  for (int i = 0; i < n; ++i) {
    vector<pair<int, int> > v;
    for (int j = 0; j < m; ++j) {
      if (cnt[j] == 0) {
        continue;
      }
      v.push_back(make_pair(a[j], j));
    }
    sort(v.begin(), v.end(), greater<pair<int, int> >());
    int x = s[i] - 'a', mask = (1 << m) - 1;
    for (pair<int, int> p : v) {
      int y = p.second;
      if (A[x][y] == 0) {
        if (x < y) {
          Mark(mask, x, y);
        } else {
          Mark(mask, y, x);
        }
      }
      mask ^= (1 << y);
    }
    a[x] = i;
    ++cnt[x];
  }
  for (int mask = (1 << m) - 2; mask > -1; --mask) {
    if (dp[mask]) {
      continue;
    }
    bool value = true;
    for (int k = 0; k < m; ++k) {
      if ((mask & (1 << k)) > 0) {
        continue;
      }
      value &= dp[(mask | (1 << k))];
    }
    dp[mask] = value;
  }
  int ans = n;
  for (int mask = 0; mask < (1 << m); ++mask) {
    if (dp[mask]) {
      continue;
    }
    int ansx = 0;
    for (int k = 0; k < m; ++k) {
      if ((mask & (1 << k)) == 0) {
        continue;
      }
      ansx += cnt[k];
    }
    ans = min(ans, ansx);
  }
  printf("%d\n", ans);
  return 0;
}
