#include <iostream>
#include <cstdio>

using namespace std;

const int N = 1 << 20; // za svaki slucaj.
const int M = 400000; // segtree offset za nulu

// ----------
// max-segtree

int tree[2 * N];

void update(int pos, int x)
{
    pos += N + M;
    if(tree[pos] > x) return; // nothing to be done here
    tree[pos] = x;
    for(pos /= 2; pos; pos /= 2)
        tree[pos] = max(tree[pos * 2], tree[pos * 2 + 1]);
}

int query(int a, int b)
{
    a += N + M;
    b += N + M;
    int res = max(tree[a], tree[b]);
    while(a / 2 != b / 2)
    {
        if(a % 2 == 0) res = max(res, tree[a + 1]);
        if(b % 2 == 1) res = max(res, tree[b - 1]);
        a /= 2;
        b /= 2;
    }
    return res;
}

// ----------

char s[N];
int a[N], b[N]; // broj 'a' i 'b' pre s[i], ukljucujuci s[i]
int d[N];

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

    int n, m;
    scanf("%i %i",&n,&m);
    m--;
    for(int i = 0; i < n; i++)
        scanf(" %c",&s[i]);

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

    if(s[0] == 'a')
    {
        d[0] = 1;
        update(1, 1);
    }
    for(int i = 1; i < n; i++)
    {
        d[i] = 1 + query(0, a[i] - b[i]);
        update(a[i] - b[i], d[i]);
    }

    int res = 0;
    for(int i = 0; i < m; i++)
        if(a[n - 1] - a[i] >= b[n - 1] - b[i])
            res = max(res,d[i]);

    printf("%i\n",res);

    return 0;
}
