#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int l = 0, r = 0;
  int k1 = k, k2 = k, mx = -1;
  while (r < n) {
    if (s[r] == 'a')
      r++;
    else {
      if (k1 > 0) {
        r++;
        k1--;
      } else {
        if (mx < r - l) mx = r - l;
        while (k1 <= 0 and l <= r) {
          if (s[l] == 'b') k1++;
          l++;
        }
      }
    }
  }
  if (mx < r - l) mx = r - l;
  l = 0, r = 0;
  while (l < n and r < n) {
    if (s[r] == 'b')
      r++;
    else {
      if (k2 > 0) {
        r++;
        k2--;
      } else {
        if (mx < r - l) mx = r - l;
        while (k2 <= 0 and l <= r) {
          if (s[l] == 'a') k2++;
          l++;
        }
      }
    }
  }
  if (mx < r - l) mx = r - l;
  cout << mx << endl;
  return 0;
}
