#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int mx = 0;
  vector<int> freqa(2, 0), freqb(2, 0);
  int ja = 0, jb = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'a') {
      ++freqa[0];
      ++freqb[0];
    } else {
      ++freqa[1];
      ++freqb[1];
    }
    if (freqa[1] > k) {
      mx = max(mx, freqa[0] + freqa[1] - 1);
      while (freqa[1] > k) {
        if (s[ja] == 'a')
          --freqa[0];
        else
          --freqa[1];
        ++ja;
      }
    }
    if (freqb[0] > k) {
      mx = max(mx, freqb[1] + freqb[0] - 1);
      while (freqb[0] > k) {
        if (s[jb] == 'a')
          --freqb[0];
        else
          --freqb[1];
        ++jb;
      }
    }
  }
  mx = max(mx, freqa[0] + freqa[1]);
  mx = max(mx, freqb[1] + freqb[0]);
  cout << mx;
  return 0;
}
