#include<stdio.h>

using namespace std;

const int MAXN=300000;

char c[MAXN];
int n,m;

int dp[MAXN];
int min;

int deli(int x)
{
    if(dp[x]!=-2) return dp[x];
    int p=0;
    int s=-1;
    int _x=x;
    while(x>min)
    {
              if(c[x]=='b') p--;
              else p++;
              x--;
              if(p>=0) 
              {
                      // printf("%d\n",x);
                       int l=deli(x)+1;
                       if(l>s && l>=0) s=l;  
                              
              }          
    }    
    dp[_x]=s;
    return s;
}




int main()
{
    FILE *f,*g;
    f=fopen("muzej.in","r");
    g=fopen("muzej.out","w");
    fscanf(f,"%d %d",&n,&m);
    m--;
    fscanf(f,"%s",&c);
    int x=0;
    for(int i=0; i<n; i++) dp[i]=-2;
    for(int i=m; i<n; i++)
    {
            if(c[i]=='a') x++;
            else x--;        
    }
    m--;
    while(m>=0 && c[m]=='b' && x>0)
    {
               m--;
               x--;
    }
    min=0;
    int _i;
    if(c[min]=='a') _i=1;
    else _i=-1;
    while(_i<0)
    {
               min++;
               if(c[min]=='a') _i=1;
               else _i=-1;     
    }
    dp[min]=1;
    int s=0;
    if(min<m) s=deli(m);
    fprintf(g,"%d",s);
    
    /*
    for(int i=0; i<=m; i++) printf("%d\n",dp[i]);
    
    printf("\n\n%d",m);
    
    scanf("%d",&n);
    */
    fclose(f);
    fclose(g);
}
