#include <cstdio>
#include <cstring>
#include <algorithm>
#define OFS 300005
using namespace std;

char A[300005];
int D[300005],Preth[300005];
int         Sponzor[300005];
int P[300005];

int Pojav[600010];

int N,M,i,j,k,opt,optp,sol,dje;

inline int vadi(int l,int r){
   return P[r] - P[l-1];
}

void solvemali(){
   for (i=2; i<=N; i++){
      if (vadi(1,i)>=0){
         opt = 0;
         optp = 0;
         for (j=0; j<i; j++){
            if (vadi(j+1,i)>=0){
               if (D[j]>opt){
                  opt = D[j];
                  optp = j;
               }
            }
         }
         D[i] = opt + 1;
         if (opt != 0) Preth[i] = optp;
         if (Preth[i] < M && M<=i){
            if (opt > sol){
               sol = opt;
               dje = i;
            }
         }
      }
   }
   //for (i=1; i<=N; i++) printf(" %d %d %d\n",i,D[i],Preth[i]);
   //for (i=1; i<=N; i++) printf("%d\n",D[i]);
   printf("%d\n",sol);
}

void zdrndajsponzore(){
   int i,j,k,l;
   for (i=1; i<=N; i++){
      Sponzor[i] = Pojav[P[i] + OFS];
      Pojav[P[i] + OFS] = i;
   }
}

void solveprobni(){
   zdrndajsponzore();
   for (i=2; i<=N; i++){
      if (vadi(1,i)>=0){
         if (A[i]=='b'){
            D[i] = D[Sponzor[i]]+1;
            Preth[i] = Sponzor[i];
         } else {
            if (D[Sponzor[i]] > D[i-1]){
               D[i] = D[Sponzor[i]]+1;
               Preth[i] = Sponzor[i];
            } else {
               D[i] = D[i-1]+1;
               Preth[i] = i-1;
            }
         }
         if (Preth[i] < M && M<=i){
            //printf("kandidat %d\n",i);
            if (D[i]-1 > sol){
               sol = D[i]-1;
               dje = i;
            }
         }
      }
   }
   //for (i=1; i<=N; i++) printf(" %d %d %d %d\n",i,D[i],Preth[i],Sponzor[i]);
   //for (i=1; i<=N; i++) printf("%d\n",D[i]);
   printf("%d\n",sol);
}




int main(){
   freopen("muzej.in","r",stdin);
   freopen("muzej.out","w",stdout);
   scanf("%d%d%s",&N,&M,A+1);
   for (i=1; i<=N; i++) P[i] = P[i-1] + 2*'a' + 1 - 2*A[i];
   if (A[1]=='a') D[1]=1;
   if (N<=5999) solvemali(); else solveprobni();
   return 0;
}





