#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5+5;
const int inf = 1e9;

char s[maxn];
int n,k,dp[1<<17],pos[maxn][17];


bool check(int x){
	for(int j=0;j<k;++j){
		int now=0;
		pos[n+1][j]=-1;
		for(int i=n;i>=1;--i){
			if(s[i]=='?' || s[i]-'a'==j){
				now++;
			}else now=0;
			if(now>=x){
				pos[i][j]=i;
			}else pos[i][j]=pos[i+1][j];
		}
	}
	for(int i=0;i<(1<<k);++i)dp[i]=inf;
	dp[0]=0;
	for(int i=0;i<(1<<k)-1;++i){
		if(dp[i]==inf)continue;
		for(int j=0;j<k;++j){
			if(!((i>>j)&1) && pos[dp[i]+1][j]!=-1){
				dp[i^(1<<j)]=min(dp[i^(1<<j)],pos[dp[i]+1][j]+x-1);
			}
		}
	}
	return dp[(1<<k)-1]!=inf;
}
int main(){
	scanf("%d%d%s",&n,&k,s+1);
	int l=0,r=n,ans=-1;
	while(l<=r){
		int mid=l+r>>1;
		if(ans==mid || check(mid)){
			ans=mid;
			l=mid+1;
		}else r=mid-1;
	}
	printf("%d\n",ans);
} 