/* dont stick to an approach */

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <array>
#include <unordered_set>
#include <stack>
#include <unordered_map>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <bitset>
#include <chrono>
#include <random>
#include <fstream>

using namespace std;

typedef int ll;
typedef unsigned long long int ull;
typedef long double ldb;

#define PB push_back

#define For(i, n) for (ll i = 0; i < n; i++)

#define trav(a,x) for (auto& a : x)

#define PYES cout<<"YES\n"
#define PNO cout<<"NO\n"
#define PYes cout<<"Yes\n"
#define PNo cout<<"No\n"
//#define endl '\n'

#define sq(x)           (x*x)

#define vll             vector<ll>
#define pll             pair<ll,ll>
#define ff              first
#define ss              second
#define rev(v)          reverse(v.begin(),v.end())
#define srt(v)          sort(v.begin(),v.end())
#define grtsrt(v)       sort(v.begin(),v.end(),greater<ll>())
#define mnv(v)          *min_element(v.begin(),v.end())
#define mxv(v)          *max_element(v.begin(),v.end())
#define all(v)          v.begin(),v.end()
#define ACC(v)          accumulate(v.begin(),v.end(),0ll)

#define eps             1e-9

const double PI=acos(-1.0);

#define Fas ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

mt19937 rng((unsigned int)chrono::steady_clock::now().time_since_epoch().count());

//--------------------------------------------functions-------------------------------------------------//

ll power(ll a,ll b){ll result=1;while(b>0){if(b%2 == 1){result *= a;} a *= a;b /= 2;}return result;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
ll countSetBits(ll x){ll Count=0;while(x>0){if(x&1) Count++;x=x>>1;}return Count;}
bool isPerfectSquare(ll n){ll sr = sqrt(n);if (sr * sr == n)return true;else return false;}
ll mod(ll x,ll M){return ((x%M + M)%M);}
ll add(ll a, ll b,ll M){return mod(mod(a,M)+mod(b,M),M);}
ll mul(ll a, ll b,ll M){return mod(mod(a,M)*mod(b,M),M);}
ll powerM(ll a,ll b,ll M){
    ll res=1ll;
    while(b){
        if(b%2ll==1ll){
            res=mul(a,res,M);
        }
        a=mul(a,a,M);b/=2ll;
    }
    return res;
}
ll mod_inv(ll a, ll m) {
    ll g = m, r = a, x = 0, y = 1;
    while (r != 0) {
        ll q = g / r;
        g %= r; swap(g, r);
        x -= q * y; swap(x, y);
    }
    return mod(x,m);
}


//------------------------------------sieve of erantothenes-----------------------------------------------//
//ll MAXN=1e7+150;
//vector<ll> fact(MAXN+1);
//void sieve_of_erantothenes()
//{
//    fact[1] = 1;
//    for (ll i = 2; i <= MAXN; i++)
//        fact[i] = i;
//    for (ll i = 4; i <= MAXN; i += 2)
//        fact[i] = 2;
//    for (ll i = 3; i * i <= MAXN; i++){
//        if (fact[i] == i){
//            for (ll j = i * i; j <= MAXN; j += i)
//                if (fact[j] == j)
//                    fact[j] = i;
//        }
//    }
//}
//----------------------------------------nCr mod------------------------------------------------------//
ll nCr(ll n, ll k){
    if(n<k) return 0;
    if(k==0) return 1;
    ll res = 1;
    if (k > n - k) k = n - k;
    for(ll i = 0; i < k; ++i){
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll modInverse(ll n,ll M){
    return powerM(n,M-2,M);
}

vector<ll> factu;
void factcalc(ll n,ll M){
    factu.resize(n+1);
    factu[0]=1;
    for(ll i=1;i<=n;i++){
        factu[i]=mul(factu[i-1],i,M);
    }
}
ll nCrM(ll n,ll r,ll M){
    if(n<r) return 0;
    if(r==0) return 1;
    return mul(mul(factu[n],modInverse(factu[r],M),M),modInverse(factu[n-r],M),M);
}
ll rand_int(ll l, ll r){
    return uniform_int_distribution<ll>(l, r)(rng);
}
//-----------------------------------------------solve-----------------------------------------------------//

void solve(){
    ll n,k;cin>>n>>k;
    string s;cin>>s;
    ll low=1,high=n;
    ll ans=0;
    auto check = [&](ll len)->bool{
        vector<vector<ll>> pos(k,vector<ll> (n+2));
        for(ll i=0;i<k;i++){
            pos[i][n]=pos[i][n+1]=n+1;
            ll l=0;
            for(ll j=n-1;j>=0;j--){
                if(s[j]=='?' || s[j]=='a'+i){
                    l++;
                }else{
                    l=0;
                }
                if(l>=len){
                    pos[i][j]=j+len;
                }else{
                    pos[i][j]=pos[i][j+1];
                }
            }
        }
        vector<ll> dp(1<<k,n+1);
        dp[0]=0;
        for(ll i=0;i<(1<<k);i++){
            for(ll j=0;j<k;j++){
                if(i&(1<<j)){
                    continue;
                }
                dp[(1<<j)|i]=min(dp[(1<<j)|i],pos[j][dp[i]]);
            }
        }
        if(dp.back()<=n){
            return true;
        }else{
            return false;
        }
    };
    while(low<=high){
        ll m=(low+high)/2;
        if(check(m)){
            ans=m;
            low=m+1;
        }else{
            high=m-1;
        }
    }
    cout<<ans<<endl;
}

int main(){
    Fas;

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cout<<fixed<<setprecision(20);

//    ll t=0;
//    cin>>t;
//    while(t--)

        solve();

    return 0;
}
