#include <stdio.h>
#include <algorithm>

using namespace std;

int niz[ 300001 ];

int main()
{
    freopen( "muzej.in", "r", stdin );
    freopen( "muzej.out", "w", stdout );

    int n, m, ap = 0, bp = 0, a = 0, b = 0, res = 0;

    scanf("%d%d", &n, &m );
    m --;

    char s[ 300001 ];

    scanf("%s", s );

    for ( int i = m + 1; i < n; i ++ )

        if ( s[ i ] == 'a' ) ap ++;

        else bp ++;

    while ( ap != bp && m >= 0 )
    {
        if ( s[ m ] == 'b' ) bp ++;

        else ap ++;

        m --;
    }

    s[ m + 1 ] = 'k';

    int idx = 0, br = 0, vis = 0;

    for ( int i = 0; i <= m; i ++ )
    {
        br ++;

        if ( s[ i ] == 'a' ) vis ++;

        else vis --;

        if ( s[ i ] != s[ i + 1 ] )
        {
            if ( s[ i ] == 'a' ) niz[ idx ] = br;

            else niz[ idx ] = - br;

            idx ++;

            br = 0;
        }
    }

    //for ( int i = 0; i < idx; i ++ ) printf("%d\n", niz[ i ] );

    //printf("\n");

    int i = 0;

    while ( i < idx )
    {
        if ( abs( niz[ i ] ) < abs( niz[ i + 1 ] ) )
        {
            res ++;

            niz[ i + 1 ] += niz[ i ];

            i ++;
        }
        else if ( abs( niz[ i ] ) == abs( niz[ i + 1 ] ) )
        {
            res ++;

            i += 2;
        }
        else
        {
            if ( niz[ i ] > 0 )
            {
                int r = abs( niz[ i ] ) - abs( niz[ i + 1 ] );

                if ( r > vis )
                {
                    niz[ i ] -= vis;

                    res += vis;

                    vis = 0;

                    niz[ i + 2 ] += niz[ i + 1 ] + niz[ i ];

                    i += 2;

                    continue;
                }
                else
                {
                    niz[ i ] -= r;

                    vis -= r;

                    res += r;

                    continue;
                }
            }

            int s = 0, j = i;

            for ( ; j < idx; j ++ )
            {
                s += niz[ j ];

                if ( s >= 0 ) break;
            }

            if ( s == 0 ) i = j + 1;

            else
            {
                i = j;

                niz[ i ] = s;
            }

            res ++;
        }
    }

  //  for ( int i = 0; i < idx; i ++ ) printf("%d\n", niz[ i ] );

    printf("%d", res );

    return 0;
}
