#include<bits/stdc++.h>
using namespace std;
const int mxb=18,mxn=1<<mxb;
char ch[mxn];
int ne[mxb][mxn],dp[mxn],n,k;
bool ok(const int x){
    if(x<=0)return true;
    const int u=1<<k;
    for(int i=0;i<k;++i){
        const char c='a'+i;
        for(int j=n,cnt=0;j;--j){
            cnt+=(ch[j]==c||ch[j]=='?');
            if(j+x<=n)cnt-=(ch[x+j]==c||ch[x+j]=='?');
            ne[i][j]=(cnt==x?j:ne[i][j+1]);
        }
    }
    for(int mask=1;mask<u;++mask){
        dp[mask]=-1;
        for(int i=0;i<k;++i)if(mask>>i&1){
            const int cmask=mask^(1<<i),nxt=dp[cmask];
            if(nxt==-1)continue;
            if(ne[i][nxt+1]!=-1 && (dp[mask]==-1||dp[mask]>ne[i][nxt+1]+x-1)){
                dp[mask]=ne[i][nxt+1]+x-1;
            }
        }
    }
    return dp[u-1]!=-1;
}
int main(){
    scanf("%d%d",&n,&k);
    scanf("%s",ch+1);
    for(int i=0;i<k;++i)ne[i][n+1]=-1;
    int low=-1,high=n+10,mid;
    while(high-low>1){
        mid=(low+high)/2;
        if(ok(mid))low=mid;
        else high=mid;
    }
    printf("%d\n",low);
}