#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  scanf("%d%d", &n, &d);
  string s;
  cin >> s;
  int cost = 0, sum = 0, mx = -1;
  for (int i = 0, j = 0; j < n;) {
    if (s[j] == 'a') {
      j++;
      sum++;
      mx = max(sum, mx);
    } else if (s[j] == 'b' && cost < d) {
      cost++;
      sum++;
      j++;
      mx = max(sum, mx);
    } else {
      sum--;
      if (s[i] == 'b') cost--;
      i++;
    }
  }
  cost = 0, sum = 0;
  for (int i = 0, j = 0; j < n;) {
    if (s[j] == 'b') {
      j++;
      sum++;
      mx = max(sum, mx);
    } else if (s[j] == 'a' && cost < d) {
      cost++;
      sum++;
      j++;
      mx = max(sum, mx);
    } else {
      sum--;
      if (s[i] == 'a') cost--;
      i++;
    }
  }
  cout << mx << endl;
}
