#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e12 + 1;
bool function1(string s, int k, int val) {
  int a = 0, b = 0;
  for (int i = 0; i < k; i++) {
    if (s[i] == 'a')
      a += 1;
    else
      b += 1;
  }
  if (min(a, b) <= val) return true;
  for (int i = k; i < s.size(); i++) {
    if (min(a, b) <= val) return true;
    if (s[i] == 'a')
      a += 1;
    else
      b += 1;
    if (s[i - k] == 'a')
      a -= 1;
    else
      b -= 1;
  }
  if (min(a, b) <= val) return true;
  return false;
}
int main() {
  int t;
  t = 1;
  while (t--) {
    int n, m, ans = 0;
    cin >> n >> m;
    string s;
    cin >> s;
    int l = 1;
    int r = n;
    while (l <= r) {
      int mid = l + (r - l) / 2;
      if (function1(s, mid, m)) {
        ans = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
