#include <cstdio>
#include <algorithm>

using namespace std;

const int MaxN = 3e5 + 35;

int n, m, cntA, cntB, uzeoA, uzeoB, ret;
char s[ MaxN ];

void solve()
{
  int ret = 0, en = n - 1;
  for ( int mask = 0; mask < 1 << en; mask++ )
  {
    int cntA = 0, cntB = 0, temp = 0;
    bool ok = true;
    for ( int i = 0; i < n; i++ )
    {
      s[ i ] == 'a' ? cntA++ : cntB++;
      if ( mask & 1 << i )
      {
        ok &= cntA >= cntB;
        cntA = cntB = 0;
        if ( i < m - 1 ) temp++;
      }
    }
    ok &= cntA >= cntB;
    if ( ok ) ret = max( ret, temp );
  }
  printf( "%d\n", ret );
}

int main()
{
  freopen( "muzej.in", "r", stdin );
  freopen( "muzej.out", "w", stdout );
  scanf( "%d %d %s", &n, &m, s );
  if ( n < 20 )
  {
    solve();
    return 0;
  }
  for ( int i = 0; i < n; i++ ) s[ i ] == 'a' ? cntA++ : cntB++;
  for ( int i = 0; i < m - 1; i++ )
  {
    if ( s[ i ] == 'a' ) cntA--, uzeoA++;
    else cntB--, uzeoB++;
    if ( cntA >= cntB && uzeoA >= uzeoB ) ret++, uzeoA = uzeoB = 0;
  }
  printf( "%d\n", ret );
  return 0;
}
