#include <bits/stdc++.h>
using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int mod = 1e9+7;
int sum(int a, int b){return (a+b) % mod;}
int sub(int a, int b){return (a + mod - b) % mod;}
int mul(int a, int b){return (1ll * a * b) % mod;}
int power(int a,int b){
	int res = 1;
	while(b){
		if(b&1)res = mul(res,a);
		b >>= 1;
		a = mul(a,a);
	}
	return res;
}

const int maxn = 2e5+5;
const int maxk = 18;
const int oo = 1e9;

int N,K,memo[(1<<maxk)],sig[maxk][maxn],ac[maxk][maxn];
char A[maxn];

int dp(int mask){
	if(mask == 0)return 0;
	if(__builtin_popcount(mask) == 1){
		forn(i,0,K)if(mask&(1<<i))return sig[i][0];
	}
	int &res = memo[mask];
	if(res != -1)return res;
	res = oo;
	forn(i,0,K){
		if(!(mask&(1<<i)))continue;
		int mini = dp(mask^(1<<i))+1;
		if(mini <= N-1)
			res = min(res,sig[i][mini]);
	}
	return res;
	
}
int get(int i,int j,int k){
	int res = ac[k][j];
	if(i)res -= ac[k][i-1];
	return res;
}
int can(int len){
	forn(i,0,K){
		forr(j,N-1,0){
			sig[i][j] = oo;
			if(j+1 <= N-1)sig[i][j] = min(sig[i][j],sig[i][j+1]);
			if(j+len-1 <= N-1){
				int s = get(j,j+len-1,i)+get(j,j+len-1,17);
				if(s == len)sig[i][j] = min(sig[i][j],j+len-1);
			}
		}
	}
	memo[0] = 0;
	forn(mask,1,(1<<K)){
		if(__builtin_popcount(mask) == 1){
			forn(i,0,K)if(mask&(1<<i))memo[mask] = sig[i][0];
			continue;
		}
		int &res = memo[mask];
		res = oo;
		forn(i,0,K){
			if(!(mask&(1<<i)))continue;
			int mini = memo[mask^(1<<i)]+1;
			if(mini <= N-1)
				res = min(res,sig[i][mini]);
		}
	}
	return memo[(1<<K)-1] <= N-1;
	//forn(i,0,(1<<K))memo[i] = -1;
	//int res = dp((1<<K)-1);
	//return res <= N-1;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> K;
	forn(i,0,N)cin >> A[i];
	forn(i,0,N){
		int add = (A[i] == '?');
		ac[17][i] = add;
		if(i)ac[17][i] += ac[17][i-1];
	}
	forn(i,0,K){
		char c = (char)(i+'a');
		forn(j,0,N){
			int add = (c == A[j]);
			ac[i][j] = add;
			if(j)ac[i][j] += ac[i][j-1];
		}
	}
	int ini = 0,fin = N+1;
	while(ini < fin){
		int mit = (ini+fin)>>1;
		if(!can(mit))fin = mit;
		else ini = mit+1;
	}
	cout << ini-1 << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/
