#include <bits/stdc++.h>
using namespace std;
void openFiles() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
long long int n, k;
string s;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  cin >> s;
  long long int mx = 0;
  long long int l = 0, r = 0;
  map<char, long long int> mp;
  while (r < n) {
    mp[s[r]]++;
    if (mp['a'] <= k || mp['b'] <= k) {
      r++;
    } else {
      mx = max(mx, r - l);
      mp[s[r]]--;
      mp[s[l]]--;
      l++;
    }
  }
  mx = max(mx, r - l);
  cout << mx;
  return 0;
}
