#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAX_N = 300005;

int n, m;
int dp[MAX_N];
int best[2 * MAX_N];
char str[MAX_N];

void update(int pos, int by) {
    for (int i = pos + MAX_N; i < 2 * MAX_N; i += i & -i)
        best[i] = max(best[i], by);
}

int get(int pos) {
    int ret = 0;
    for (int i = pos + MAX_N; i > 0; i -= i & -i)
        ret = max(ret, best[i]);
    return ret;
}

int main() {
    memset(best, 0, sizeof(best));
    freopen("muzej.in", "r", stdin);
    freopen("muzej.out", "w", stdout);
    scanf("%d%d", &n, &m);
    scanf("%s", &str);
    --m;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        if (str[i] == 'a') ++sum;
        else --sum;
        dp[i] = get(sum) + 1;
        update(sum, dp[i]);
    }
    sum = 0;
    for (int i = n - 1; i >= m; --i)
        if (str[i] == 'a') ++sum;
        else --sum;
    int res = 0;
    for (int i = m - 1; i >= 0; --i) {
        if (dp[i] > res && sum >= 0) res = dp[i];
        if (str[i] == 'a') ++sum;
        else --sum;
    }
    printf("%d\n", res);
    return 0;
}
