#include<bits/stdc++.h>
#define For(i,a,b)for(int i=a;i<=b;++i)
#define Rof(i,a,b)for(int i=a;i>=b;--i)
using namespace std;
const int N=2e5+5,M=1<<17;
int n,k,ans,f[M],sum[N][18],nxt[N][18];char s[N];
inline bool check(int x){
	For(i,0,k-1)nxt[n+1][i]=n+1;
	Rof(i,n,1)For(j,0,k-1){
		if(i+x-1<=n&&sum[i+x-1][k]-sum[i-1][k]+sum[i+x-1][j]-sum[i-1][j]==x)nxt[i][j]=i;
		else nxt[i][j]=nxt[i+1][j];
	}
	For(i,0,(1<<k)-1)f[i]=n+1;f[0]=0;
	For(i,0,(1<<k)-1)if(f[i]<=n)For(j,0,k-1)if(!(i>>j&1))f[i|(1<<j)]=min(f[i|(1<<j)],min(n+1,nxt[f[i]+1][j]+x-1));
    return f[(1<<k)-1]<=n;
}
int main(){
	cin>>n>>k>>s+1;
	For(i,1,n){
		For(j,0,k)sum[i][j]=sum[i-1][j];
		sum[i][s[i]=='?'?k:s[i]-'a']++;
	}
	for(int l=0,r=n,mid=l+r>>1;l<=r;mid=l+r>>1)check(mid)?ans=mid,l=mid+1:r=mid-1;
	return printf("%d\n",ans),0;
}