
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 

const int mxx=200010;
int a[mxx][18];
int dp[(1ll<<17)+2];

int main(){

            string s;
            int n;
            int k;
            cin>>n>>k;
            cin>>s;
            int low=0;
            int high=n/k;
            int mid=0;
            int ans=0;

            while(low<=high){
                

                    mid=(low+high)>>1;
                    for(int i=0;i<k;i++){
                        for(int j=n-1;j>=0;j--){
                            if(s[j]=='?'||s[j]-'a'==i){
                                a[j][i]=a[j+1][i]+1;
                            }
                            else a[j][i]=0;
                        }
                        int last=n+3;
                        for(int j=n-1;j>=0;j--){
                            if(a[j][i]>=mid){
                                a[j][i]=j+mid;
                                last=a[j][i];
                            }
                            else a[j][i]=last;
                           }
                        }
                        int N=(1<<k)-1;
                        for(int j=0;j<=N;j++)dp[j]=n+3;
                        dp[0]=0;
                        for(int i=0;i<=N;i++){
                            for(int j=0;j<k;j++){
                                  int x=(1<<j);
                                  x=x&i;
                                  if(!x and a[dp[i]][j]<=n and dp[i]<n) dp[i|(1<<j)]=min(dp[i|(1<<j)],a[dp[i]][j]);
                            }
                        }
                        if(dp[N]<=n){
                                    ans=max(ans,mid);
                                    low=mid+1;
                        }
                        else high=mid-1;
            }
            cout<<ans<<"\n";
}

//i have solved this problem  after reading tutorial //