#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<long long int> a(n, 0), b(n, 0);
  long long int i, j, sum1 = 0, sum2 = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == 'a')
      sum1++;
    else
      sum2++;
    a[i] = sum1;
    b[i] = sum2;
  }
  long long int max_len = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == 'b') {
      j = upper_bound(a.begin(), a.end(), a[i] + k) - a.begin();
    } else
      j = upper_bound(a.begin(), a.end(), a[i] + k - 1) - a.begin();
    max_len = max(max_len, j - i);
  }
  for (i = 0; i < n; i++) {
    if (s[i] == 'a') {
      j = upper_bound(b.begin(), b.end(), b[i] + k) - b.begin();
    } else
      j = upper_bound(b.begin(), b.end(), b[i] + k - 1) - b.begin();
    max_len = max(max_len, j - i);
  }
  cout << max_len << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
}
