
#include <bits/stdc++.h>

using namespace std;

#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 2e5+5;
const int K = 20;

int n , k , pre[K][N] , pos[K][N] , dp[1<<K];
string s;

bool check(int len)
{
     for(int i=0; i<k; i++)
     {
         pos[i][n+1] = n+1;
         for(int j=n; j>=0; j--)
         {
             if (pre[i][min(n , j+len)] - pre[i][j] == len)
                 pos[i][j] = j+len;
             else pos[i][j] = pos[i][j+1];
         }
     }

     //memset(dp , '?' , sizeof(dp));
     dp[0] = 0;
     for(int msk=1; msk < (1<<k); msk++)
     {
         dp[msk] = n+1;
         for(int j=0; j<k; j++)
         {
             if ((1<<j)&msk)
             {
                 dp[msk] = min(dp[msk] , pos[j][dp[msk^(1<<j)]]);
             }
         }
     }

    return dp[(1<<k)-1] <= n;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> k >> s;

    s = ' '+s;
    for(int i=0; i<k; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if (s[j]=='?' || s[j]-'a'==i) pre[i][j]=1;
            pre[i][j] += pre[i][j-1];
        }
    }

    int l=1 , h=n , mid , ans=0;

    while(l<=h)
    {
        mid = (l+h)/2;
        if (check(mid))
        {
            ans = mid;
            l = mid+1;
        }
        else h=mid-1;
    }

    cout << ans << '\n';

    return 0;
}
