#include <cstdlib>
#include <iostream>
#include <stdio.h>

using namespace std;

int n,m;
int red[300005];

int main(int argc, char *argv[])
{
    FILE *in;
    FILE *out;
    in=fopen("muzej.in","r");
    out=fopen("muzej.out","w");
    fscanf(in,"%d",&n);
    fscanf(in,"%d",&m);
    m--;
    //printf("%d %d\n",n,m);
    for(int i=0; i<n; i++)
     {
         char c;
         fscanf(in,"%c",&c);
         while(c!='a' && c!='b') fscanf(in,"%c",&c);
         //printf("%c",c);
         if(c=='a') red[i]=1;
         if(c=='b') red[i]=-1;
     }
    /*printf("\n");
    for(int i=0; i<n; i++) printf("%d ",red[i]);
    printf("\n");*/
    int R=0;
    for(int i=n-1; i>=m; i--) R+=red[i];
    int L=0;
    for(int i=0; i<m; i++) L+=red[i];
    int pos=m-1;
    while(R<0 || L<0 || (R>0 && red[pos]==-1))
     {
         R+=red[pos];
         L-=red[pos];
         pos--;
     }
    pos++;
    while(L<0)
     {
         L+=red[pos];
         R-=red[pos];
         pos++;
     }
    //printf("%d:  %d %d\n",pos,L,R);
    int cnt=0,b=0,cur=0;
    for(int i=0; i<pos; i++)
     {
         if(red[i]==1)
          {
              cur+=1-b;
              cnt++;
              //if(cur>=0) cnt++;
              b=0;
          }
         else
          {
              b++;
              if(b>1) cnt--;
              if(b==2 && cur>0) cnt++;
              //if(b==2) cnt++;
          }
         //printf("%d:  %d  | %d %d   b:%d\n",i,red[i],cur,cnt,b);
     }
    fprintf(out,"%d\n",cnt);
    fclose(in);
    fclose(out);
    system("PAUSE");
    return 0;
}
