#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  int k;
  cin >> n >> k;
  string s;
  cin >> s;
  int a[n];
  for (int i = 0; i < n; i++) {
    if (s[i] == 'a')
      a[i] = 1;
    else
      a[i] = -1;
  }
  int l = 0, r = 0;
  int total = 0;
  int k1 = k;
  int cmax = 0;
  while (r < n) {
    if (a[r] == 1) {
      total += 1;
      r++;
    } else {
      if (k1 > 0) {
        total++;
        r++;
        k1--;
      } else {
        if (l < r) {
          if (a[l] == 1) {
            total--;
            l++;
          } else {
            k1++;
            l++;
            total--;
          }
        } else {
          l++;
          r++;
        }
      }
    }
    cmax = max(cmax, total);
  }
  int a1[n];
  for (int i = 0; i < n; i++) {
    if (s[i] == 'b')
      a1[i] = 1;
    else
      a1[i] = -1;
  }
  int l1 = 0, r1 = 0;
  int total1 = 0;
  int k2 = k;
  int cmax1 = 0;
  while (r1 < n) {
    if (a1[r1] == 1) {
      total1 += 1;
      r1++;
    } else {
      if (k2 > 0) {
        total1++;
        r1++;
        k2--;
      } else {
        if (l1 < r1) {
          if (a1[l1] == 1) {
            total1--;
            l1++;
          } else {
            k2++;
            l1++;
            total1--;
          }
        } else {
          l1++;
          r1++;
        }
      }
    }
    cmax1 = max(cmax1, total1);
  }
  cout << max(cmax1, cmax);
}
