#include <bits/stdc++.h>
using namespace std;
int func(string str, int k, int len) {
  int count[2];
  count[0] = 0;
  count[1] = 0;
  int n = str.length();
  int i = 0;
  for (; i < len; i++) {
    count[str[i] - 'a']++;
  }
  int index = 0;
  for (; i < n;) {
    if (count[0] <= k) {
      return 1;
    } else if (count[1] <= k) {
      return 1;
    } else {
      count[str[index] - 'a']--;
      count[str[i] - 'a']++;
      i++;
      index++;
    }
  }
  if (count[0] <= k) {
    return 1;
  } else if (count[1] <= k) {
    return 1;
  }
  return 0;
}
int BS(string str, int k) {
  int n = str.length();
  int l = 1;
  int r = n;
  int ans = INT_MIN;
  while (l <= r) {
    int m = (l + r) / 2;
    int x = func(str, k, m);
    if (x) {
      ans = max(ans, m);
      l = m + 1;
    } else
      r = m - 1;
  }
  return ans;
}
int main() {
  int n, k;
  cin >> n >> k;
  string str;
  cin >> str;
  cout << BS(str, k);
}
