#include <bits/stdc++.h>
using namespace std;
int n, k, Ti = 0, idx, a, b, t;
bool flag;
string s;
int main() {
  cin >> n >> k >> s;
  idx = a = b = 0;
  for (int i = 0; i < n; i++) {
    flag = 1;
    for (int j = idx; j < n; j++) {
      if (s[j] == 'a')
        a++;
      else
        b++;
      t = min(a, b);
      if (t > k) {
        flag = 0;
        Ti = max(Ti, b + a - 1);
        idx = j;
        if (s[j] == 'a')
          a--;
        else
          b--;
        break;
      }
    }
    if (flag) {
      Ti = max(Ti, b + a);
      break;
    } else {
      if (s[i] == 'a')
        a--;
      else
        b--;
    }
  }
  cout << Ti << endl;
  return 0;
}
