#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, l, r, ml, a, b;
  cin >> n >> k;
  string arr;
  cin >> arr;
  l = 0, r = 0, a = 0, b = 0, ml = 0;
  while (l < n && r < n) {
    if (arr[r] == 'a') {
      a++;
    } else {
      b++;
    }
    if (min(a, b) <= k) {
      r++;
      ml = max(ml, a + b);
    } else {
      while (min(a, b) > k) {
        if (arr[l] == 'a') {
          a--;
        } else {
          b--;
        }
        l++;
      }
      r++;
    }
  }
  cout << ml;
  return 0;
}
