#include <cstdio>
#include <iostream>
#include <cstdlib>

using namespace std;

const int maxN = 300005;
const int penal = -999999;

int n, m;
int a[maxN], b[maxN];

int tree[maxN];

int csum (int n) {
    int s = 0;
    int idx = n;
    while (idx > 0) {
        s += tree[idx];
        idx -= (idx & -idx); //cout << idx;
    }
    return s;
}

int sum (int i, int j) {
    return (csum(j) - csum(i-1));
}

int update (int n, int val) {
    int idx = n;
    while (idx < maxN) {
        tree[idx] += val;
        idx += (idx & -idx);
    }
}

void test () {
    int i = 1;
    int idx = 0;
    a[n+1] = penal;

    while (i <= n) {
        int zn = a[i];
        int t = 1;
        while (a[++i] == zn) { t++; }
        b[idx++] = t * zn;
    }

    int k = idx;

    for (int i = 0; i < k; ++i)
        cout << b[i] << " ";
}

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

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

    char str[maxN];
    scanf("%s", str);

    for (int i = 1; i <= n; ++i) {
        if ( str[i-1] == 'a' )
            a[i] = 1;
        else
            a[i] = -1;
    }
  //  for (int i = 1; i <= n; ++i ) cout << a[i] << endl;

    int d[maxN];
    d[0] = 0;
    for (int i = 1; i <= m; ++i) {
        int idx = i-1;

        int sum = a[i];
        if ( sum < 0 ) {
            while (idx > 0 && sum < 0) {
                sum += a[idx];
                idx--;
            }
            if ( sum < 0 ) {
                d[i] = penal;
            }
            else {
                d[i] = d[idx] + 1;
            }
        }
        else {
            int mx = penal;
            while ( idx >= 0 && sum >= 0 ) {
                if ( d[idx] > mx )
                    mx = d[idx];
                sum += a[idx];
                idx--;
            }
            d[i] = mx + 1;
        }
    }

    for (int i = 1; i <= n; ++i)
        update(i, a[i]);

    int mx = 0;
    int s = 0;
    for (int i = m+1; i <= n; ++i) {
        s += a[i];
        if (s > mx)
            mx = s;
    }

    int sol = penal;
    for (int i = 1; i < m; ++i) {
        if ( sum(i+1, m) + mx >= 0 && d[i] > sol )
            sol = d[i];
    }
    if (sol < 0) {
      //if ( sum(1,m) + mx >= 0 )
            sol = 0;
    }

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

    return 0;
}
