#include <iostream>
#include <cstring>
#include <stdio.h>
using namespace std;

#define MaxN (1<<19)

class SegmentTree {
public:
    int a[2*MaxN+10];
    int b[2*MaxN+10];
    int s[2*MaxN+10];

    SegmentTree() {
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        memset(s, 0, sizeof(s));
    }

    void Update( int node, int left, int right, int id, bool plus ) {
        if ( id < left || right < id ) return;

        if ( left == right ) {
            if ( plus ) {
                a[node] = 1;
                b[node] = 0;
                s[node] = 1;
            }
            else {
                a[node] = 0;
                b[node] = 1;
                s[node] = -1;
            }

            //printf("Update %d %d %d %d %d | %d %d %d\n",node,left,right,id,plus,s[node],a[node],b[node]);
            return;
        }

        int mid = ( left + right ) >> 1;
        Update( 2*node, left, mid, id, plus );
        Update( 2*node+1, mid+1, right, id, plus );

        s[node] = s[2*node] + s[2*node+1];
        a[node] = max( a[2*node+1], a[2*node]+s[2*node+1] );
        b[node] = max( b[2*node+1], b[2*node]+s[2*node+1] );

        //printf("Update %d %d %d %d %d | %d %d %d\n",node,left,right,id,plus,s[node],a[node],b[node]);
    }

    int Query( int node, int left, int right, int id, int sum, int &ret ) {
        //printf("%d %d %d %d %d | %d %d %d\n",node,left,right,id,sum,a[node],b[node],s[node]);

        if ( left > id ) {
            ret = 0;
            return -1;
        }
        int mid = ( left + right ) >> 1;

        if ( right > id ) {
            int sumDesno1;
            int tmp = Query( 2*node+1, mid+1, right, id, sum, sumDesno1 );
            if ( tmp != -1 ) return tmp;

            //printf("%d %d %d %d %d | %d %d %d **** %d\n",node,left,right,id,sum,a[node],b[node],s[node],sumDesno1);
            int sumDesno2;
            tmp = Query( 2*node, left, mid, id, sum-sumDesno1, sumDesno2 );
            if ( tmp != -1 ) return tmp;

            ret = sumDesno1 + sumDesno2;
            //printf("%d %d %d %d %d | %d %d %d **** %d %d\n",node,left,right,id,sum,a[node],b[node],s[node],sumDesno1,sumDesno2);
            return -1;
        }

        int pos = -1;

        if ( sum < 0 ) {
            if ( b[node] < -sum ) {
                ret = s[node];
                //printf("%d %d %d %d %d | %d %d %d **** %d\n",node,left,right,id,sum,a[node],b[node],s[node],ret);
                return -1;
            }
            if ( left == right ) return left;

            int sumDesno;
            int tmp = Query( 2*node+1, mid+1, right, id, sum, sumDesno );
            if ( tmp != -1 ) return tmp;

            tmp = Query( 2*node, left, mid, id, sum-sumDesno, sumDesno );
            if ( tmp != -1 ) return tmp;

            return left;
        }
        else {
            if ( a[node] < sum ) {
                ret = s[node];
                //printf("%d %d %d %d %d | %d %d %d **** %d\n",node,left,right,id,sum,a[node],b[node],s[node],ret);
                return -1;
            }
            //printf("%d %d %d %d %d | %d %d %d | %d\n",node,left,right,id,sum,a[node],b[node],s[node],sum);
            if ( left == right ) return left;

            int sumDesno;
            int tmp = Query( 2*node+1, mid+1, right, id, sum, sumDesno );
            if ( tmp != -1 ) return tmp;

            tmp = Query( 2*node, left, mid, id, sum-sumDesno, sumDesno );
            if ( tmp != -1 ) return tmp;

            return left;
        }
    }
};

int n,m;
char s[MaxN];

int zbir[MaxN];
SegmentTree tree;
int dp[MaxN];

int ret;

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

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

    if ( m == 0 ) {
        printf("0\n");
        return 0;
    }

    zbir[n] = 0;
    for (int i = n-1; i >= 0; --i) {
        zbir[i] = zbir[i+1];
        if ( s[i] == 'a' ) zbir[i]++;
        else               zbir[i]--;
    }

    memset(dp, -1, sizeof(dp));

    ret = 0;
    if ( s[0] == 'a' ) {
        dp[0] = 1;
        if ( zbir[1] >= 0 ) ret = 1;
    }

    tree.Update( 1, 0, MaxN, 0, s[0]=='a' );
    for (int i = 1; i < m; ++i) {

        if ( s[i] == 'a' ) {
            if ( dp[i-1] != -1 ) dp[i] = dp[i-1] + 1;

            int tmp;
            int pos = tree.Query( 1, 0, MaxN, i-1, -1, tmp );
            if ( pos > 0 ) {
                dp[i] = max( dp[i], dp[pos-1]+1 );
            }

            //printf("%d => %d %d\n",i+1,pos+(pos==-1?0:1),dp[i]);
        }
        else {
            int tmp;
            int pos = tree.Query( 1, 0, MaxN, i-1, 1, tmp );
            if ( pos > 0 ) {
                dp[i] = max( dp[i], dp[pos-1]+1 );
            }

            //printf("%d => %d %d\n",i+1,pos+(pos==-1?0:1),dp[i]);
        }

        tree.Update( 1, 0, MaxN, i, s[i]=='a' );

        if ( zbir[i+1] >= 0 ) ret = max( ret, dp[i] );
        //printf("%d => %d\n",i+1,dp[i]);
    }

    printf("%d\n",ret);

    return 0;
}
