typedef long long LL;
#include<bits/stdc++.h>

using namespace std;

bool check(string &s,int target,int n,int k)
{
    int next[n][k];
    vector<int>cnt(k,0);
    vector<int>record(k,INT_MAX);
    for(int i=n-1;i>=0;i--)
    {
        if(s[i]=='?')
        {
            for(int j=0;j<k;j++)cnt[j]=min(target,cnt[j]+1);
        }else
        {
            cnt[s[i]-'a']=min(target,cnt[s[i]-'a']+1);
            for(int j=0;j<k;j++)
            {
                if(j==(s[i]-'a'))continue;
                cnt[j]=0;
            }
        }
        for(int j=0;j<k;j++)
            if(cnt[j]==target)record[j]=min(record[j],i+cnt[j]);
        for(int j=0;j<k;j++)
            next[i][j]=record[j];
    }
    vector<int>dp((1<<k),INT_MAX);
    for(int i=0;i<k;i++)dp[1<<i]=min(dp[1<<i],next[0][i]);
    for(int i=2;i<=k;i++)
    {
        int state = (1 << i) - 1;            
        while (state < (1 << k))
        {
            for(int j=0;j<k;j++)
            {
                if(((state>>j)&1)==0)continue;
                int prev=(state^(1<<j));
                if(dp[prev]>=n)continue;
                dp[state]=min(dp[state],next[dp[prev]][j]);
            }
            int c = state & - state;
            int r = state + c;
            state = (((r ^ state) >> 2) / c) | r;
        }
    }
    return dp[(1<<k)-1]<=n;
}

void solve()
{
    int n,k;
    string s;
    cin >> n >> k >> s;
    int l=0,r=n+1;
    while(l<r)
    {
        int len=(l+r)/2;
        if(check(s,len,n,k))l=len+1;
        else r=len;
    }
    cout << l-1 << endl;
    return;
}

int main() 
{
    solve();
    // int n;
    // cin >> n;
    // for(int i=0;i<n;i++)
    //     solve();
    return 0;
}