#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int K = 17;
const int N = 200200;

int dp1[1 << K];
// int dp2[N][K];
int dp3[N][K];
int prefix[N][K];

void maximize(int& x, int y) {
    if (x < y) {
        x = y;
    }
}

int main() {
    int n, k;
    cin >> n >> k;

    string s;
    cin >> s;
    s = "?" + s;

    int answer = 0;
    int low = 1, high = n;

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

    while (low <= high) {
        int mid = low + (high - low) / 2;

        // memset(dp2, -1, sizeof(dp2));

        // for (int j = 0; j < k; j++) {
        //     dp2[0][j] = 0;
        // }

        memset(dp3, -1, sizeof(dp3));

        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < k; j++) {
                dp3[i][j] = dp3[i - 1][j];
                if (prefix[i][j] >= mid) {
                    dp3[i][j] = i - mid;
                    // dp3[i][j] = dp2[prefix[i][j] - mid][j];
                }
            }
        }

        memset(dp1, -1, sizeof(dp1));

        dp1[0] = n;

        for (int mask = 0; mask < (1 << k); mask++) {
            int i = dp1[mask];

            if (i >= 0) {
                for (int j = 0; j < k; j++) {
                    if (!(mask & (1 << j))) {
                        maximize(dp1[mask | (1 << j)], dp3[i][j]);
                    }
                }
            }
        }

        if (dp1[(1 << k) - 1] >= 0) {
            answer = mid;
            low = mid + 1;
        } else {
            high = mid - 1;
        }
    }

    cout << answer << endl;
}