#include <bits/stdc++.h>
using namespace std;
int n, p, a[17][17], mask, freq[17], ans = 1000000007;
int cost[1 << 17], dp[1 << 17];
bool iscrisp[1 << 17];
bitset<1 << 17> isadj[17][17];
string s;
void process_iscrisp() {
  for (int i = 0; i < p; i++) {
    for (int j = i; j < p; j++) {
      if (i == j) {
        int cur = 0, f = 0;
        for (int k = 0; k < n; k++) {
          if (s[k] - 'a' == i) {
            f++;
            if (f > 1) isadj[i][j][(1 << p) - 1 - cur] = 1;
            cur = 0;
          } else
            cur |= 1 << (s[k] - 'a');
        }
      } else {
        int cur = 0, f1 = 0, f2 = 0;
        for (int k = 0; k < n; k++) {
          if (s[k] - 'a' == i) {
            if (f2) isadj[i][j][(1 << p) - 1 - cur] = 1;
            f1 = 1;
            f2 = 0;
            cur = 0;
          } else if (s[k] - 'a' == j) {
            if (f1) isadj[i][j][(1 << p) - 1 - cur] = 1;
            f2 = 1;
            f1 = 0;
            cur = 0;
          } else
            cur |= 1 << (s[k] - 'a');
        }
      }
      for (int k = (1 << p) - 1; k >= 0; k--) {
        if ((k >> i) & 1 and (k >> j) & 1) {
          for (int l = 0; l < p; l++) {
            if (l == i or l == j or (k >> l) & 1)
              ;
            else if (isadj[i][j][k ^ (1 << l)])
              isadj[i][j][k] = 1;
          }
        }
      }
    }
  }
  for (int i = 0; i < 1 << p; i++) {
    iscrisp[i] = 1;
    vector<int> v;
    for (int j = 0; j < p; j++) {
      if ((i >> j) & 1) {
        v.push_back(j);
      }
    }
    for (auto first : v) {
      for (auto second : v) {
        if (isadj[first][second][i] and a[first][second] == 0) iscrisp[i] = 0;
      }
    }
  }
}
void solve() {
  cin >> n >> p >> s;
  for (auto i : s) {
    freq[i - 'a']++;
    mask |= 1 << (i - 'a');
  }
  for (int i = 0; i < p; i++) {
    for (int j = 0; j < p; j++) {
      cin >> a[i][j];
    }
  }
  process_iscrisp();
  for (int i = 0; i < 1 << p; i++) {
    for (int j = 0; j < p; j++) {
      if ((i >> j) & 1) cost[i] += freq[j];
    }
  }
  dp[mask] = 1;
  for (int i = (1 << p) - 1; i >= 0; i--) {
    if (iscrisp[i] == 0) continue;
    for (int j = 0; j < p; j++) {
      if ((i >> j) & 1)
        ;
      else
        dp[i] |= dp[i ^ (1 << j)];
    }
    if (dp[i]) ans = min(ans, cost[i]);
  }
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
