//Date: 22/02/19 21:02
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
#define inc(i,n) for (int i=0;i<n;i++)

int ok[17][17],b[17][17],ans[1<<18],cnt[17];
char ansc[17],ta[17]; int tac,ansk=1<<20;
int m; char a[100010];
vector<int> ed[17];
bool fib[1<<18],vis[17][17][1<<17];

void dfsmark(int s,int ec1, int ec2){
	inc(i,m) if (i!=ec1 && i!=ec2 && (s>>i&1)==0 && !vis[ec1][ec2][s|1<<i]){
		vis[ec1][ec2][s|1<<i]=1;
		fib[s|1<<i]=1;
		dfsmark(s|1<<i,ec1,ec2);
	}
}
void dfs(int s, int sum){
	if (ans[s]>=0) return;
	ans[s]=sum;
	//if (sum<ansk) ansk=sum,strcpy(ansc,ta);
	inc(i,m) if ((s>>i&1)==0 && !fib[s|1<<i]){
		//ta[tac++]=i+'a'; 
		dfs(s|1<<i,sum-cnt[i]);
		//tac--;
		ans[s]=min(ans[s],ans[s|1<<i]);
	}
}

int main(){
	int n; cin>>n>>m>>a;
	inc(i,n) cnt[a[i]-'a']++;
	inc(i,m) inc(j,m) cin>>ok[i][j];
	for(int i=0;i<m;i++)
    {
        for(int i0=i;i0<m;i0++)
        {
            if(!ok[i][i0])
            {
                int state=0,r=-1;
                for(int i1=0;i1<n;i1++)
                {
                    if(r==0)
                    {
                        if(a[i1]=='a'+i0)dfsmark(state,i,i0),state=0,r=1;
                        else if(a[i1]=='a'+i)state=0;
                        else state|=(1<<(a[i1]-'a'));
                    }
                    else if(r==1)
                    {
                        if(a[i1]=='a'+i)dfsmark(state,i,i0),state=0,r=0;
                        else if(a[i1]=='a'+i0)state=0;
                        else state|=(1<<(a[i1]-'a'));
                    }
                    else
                    {
                        if(a[i1]=='a'+i)r=0;
                        else if(a[i1]=='a'+i0)r=1;
                    }
                }
            }
        }
    }
	//cout<<fib[1<<'i'-'a'|1<<'f'-'a'|1];
	//inc(i,1<<m) cout<<fib[i]<<' ';cout<<'\n';
	memset(ans,-1,sizeof ans);
	dfs(0,n);
	cout<<ans[0]<<'\n';
	/*
	inc(i,m) cout<<(char)(i+'a')<<cnt[i]<<' '; cout<<'\n';
	char tt[1000];
	inc(i,strlen(ansc)){
		int tl=0;
		inc(j,strlen(a))
			if (a[j]-'a'!=ansc[i]-'a')
				tt[tl++]=a[j];
		strcpy(a,tt);
		cout<<a<<'\n';
		inc(j,strlen(a)-1)
			if (!ok[a[j]-'a'][a[j+1]-'a'])
				cout<<"!"<<j<<'\n';
	}
	cout<<ansc;*/
	return 0;
}

