#include<bits/stdc++.h>
// #define int long long
#define ld long double
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int,int>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf (int)(1e18)
#define md (int)(1e9+7)
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;

const int M = 2e5 + 10;

int n,k;
string s;
int cnt[M][17],pos[M][17];
int dp[1<<17];

bool ok(int x) {
	rep(j,0,k) {
		for(int i=n-1;i>=0;--i) {
			pos[i][j]=n+1;
			if(cnt[i][j]>=x) pos[i][j]=i+x;
			if(i+1<n) pos[i][j]=min(pos[i][j],pos[i+1][j]);
		}
	}
	rep(i,0,1<<k) dp[i]=n+1;
	dp[0]=0;
	rep(i,1,1<<k) {
		rep(j,0,k) {
			if(i&(1<<j)) {
				int x=i^(1<<j);
				if(dp[x]<n) {
					dp[i]=min(dp[i],pos[dp[x]][j]);
				}
			}
		}
	}
	return dp[(1<<k)-1]<=n;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
   	
   	cin>>n>>k;
   	cin>>s;
   	rep(i,0,n) {
   		rep(j,0,k) {
   			char x=j+'a';
   			if(s[i]==x or s[i]=='?') cnt[i][j]++;
   		}
   	}
   	rep(j,0,k) {
   		for(int i=n-2;i>=0;--i) {
   			if(!cnt[i][j]) continue;
   			cnt[i][j]+=cnt[i+1][j];
   		}
   	}
   	int lo=0,hi=n,mid,ans=0;
   	while(lo<=hi) {
   		mid=(lo+hi)>>1;
   		int now=ok(mid);
   		if(now) lo=mid+1,ans=mid;
   		else hi=mid-1;
   	}
   	cout<<ans;
   	
   	
   	
    return 0;
}