#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
void solve() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int l = 0, r = 0, ans = INT_MIN, cnt = 0;
  for (int i = 0; i < n;) {
    if (s[i] == 'b') {
      cnt++;
    }
    if (cnt > k) {
      ans = max(ans, r - l);
      if (s[l] == 'b') cnt--;
      l++;
    } else
      ans = max(ans, r - l + 1);
    i++;
    r++;
  }
  l = 0, r = 0, cnt = 0;
  for (int i = 0; i < n;) {
    if (s[i] == 'a') {
      cnt++;
    }
    if (cnt > k) {
      ans = max(ans, r - l);
      if (s[l] == 'a') cnt--;
      l++;
    } else
      ans = max(ans, r - l + 1);
    i++;
    r++;
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  int T = 1;
  while (T--) {
    solve();
    cout << '\n';
  }
  return 0;
}
