#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define FAST ios::sync_with_stdio(false);cout.tie(0);cin.tie(0);

#define ff(i,a,b) for(int (i) = (a);(i)<(b);(i)++)
#define fff(i,a,b) for(int (i) = (a);(i)<=(b);(i)++)
#define bff(i,a,b) for(int (i) = (a);(i)>(b);(i)++)
#define bfff(i,a,b) for(int (i) = (a);(i)>=(b);(i)++)

#define pb push_back
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

typedef long long int lli;

int main()
{
    FAST
    int n; cin>>n;
    int k; cin>>k;
    int counter['a'+ k+2];
    int newCounter['a'+ k+2];
    memset(counter,0,sizeof(counter));
    memset(newCounter,0,sizeof(newCounter));

    char curr,reset = 0;
    ff(i,0,n){
        cin>>curr;
        if(reset)
        newCounter[(int)curr]++;
        if(reset==curr){
            reset = 'A';
        }
        counter[(int)curr]++;
        int minimum = INT_MAX;
        int newMinimum = INT_MAX;
        ff(j,(int)'a',(int)'a'+k){
            if(minimum>counter[j]){
                minimum = counter[j];
            }
            if(newMinimum>newCounter[j] && reset != j){
                newMinimum = newCounter[j];
            }
        }
        if(minimum== 1){
            reset=curr;
        }
        if(minimum==1 || minimum==0){
            cout<<minimum+1<<endl;
        }else{
            if(newMinimum ==0){
                cout<<minimum<<endl;
            }else{
                cout<<minimum+newMinimum<<endl;
            }
        }

    }
    return 0;
}