#include <bits/stdc++.h>
#define int long long

using namespace std;

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    auto id = [&](char c) -> int {
        return (int)(c - 'a');
    };

    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;

    vector<vector<int>> freq(n + 1, vector<int>(27, 0));
    vector<int> suf(n + 1); suf[n] = 0;

    for(int i = 1; i <= n; ++i)
    {
        for(char c = 'a'; c <= 'z'; ++c)
        {
            freq[i][id(c)] = freq[i - 1][id(c)] + (c == s[i - 1]? 1 : 0);
        }
    }

    /*
    for(int i = 1; i <= n; ++i)
    {
        for(char c = 'a'; c <= 'z'; ++c)
        {
            cout << freq[i][id(c)] << " ";
        }
        cout << "\n";
    }*/

    auto interval_min = [&](int l, int r) -> int {
        int min_freq = 1e6;
        for(char c = 'a'; c < 'a' + k; ++c)
        {
            min_freq = min(min_freq, freq[r][id(c)] - freq[l - 1][id(c)]);
        }
        return 1 + min_freq;
    };

    vector<int> l(26, -1);
    for(int i = 0; i < n; ++i) {
        if(l[s[i]] == -1) {
            l[s[i]] = i;
        }
    }

    for(int i = 0; i < n; ++i)
    {
        int res = 1e6;
        for(char c = 'a'; c < 'a' + k; ++c)
        {
            if(l[s[i]] > i) continue;
            res = min(res, interval_min(l[s[i]] + 1, i + 1));
        }
        cout << res << " ";
    }
}