#include <bits/stdc++.h>
using namespace std;
double tick() {
  static clock_t oldtick;
  clock_t newtick = clock();
  double diff = 1.0 * (newtick - oldtick) / CLOCKS_PER_SEC;
  oldtick = newtick;
  return diff;
}
long long gcd(long long a, long long b) {
  if ((a == 0) || (b == 0)) return a + b;
  return gcd(b, a % b);
}
long long pow_mod(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
bool isPrime(long long a) {
  for (int i = 3; (i * i) <= a; i += 2) {
    if ((a % i) == 0) return false;
  }
  if ((a != 2) && ((a % 2) == 0)) return false;
  return true;
}
string con_ll_to_str(long long a) {
  stringstream mystr;
  mystr << a;
  return mystr.str();
}
long long con_str_to_ll(string st) {
  long long numb = 0;
  int len = st.size(), i, j = 0;
  for (i = len - 1; i >= 0; i--) {
    numb += (pow_mod(10, j) * (st[i] - '0'));
    j++;
  }
  return numb;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  queue<long long> qu, qu2;
  pair<long long, long long> opop;
  long long i, j, N, K, ans, ans2;
  string st;
  cin >> N >> K;
  cin >> st;
  ans = K;
  st = "0" + st;
  ans2 = 0;
  for (i = 1; i <= N; i++) {
    if (st[i] == 'b') {
      qu.push(i);
      if (qu.size() > K) {
        ans2 = qu.front();
        qu.pop();
        ans = ((ans) > (i - ans2) ? (ans) : (i - ans2));
      } else {
        ans = ((ans) > (i - ans2) ? (ans) : (i - ans2));
      }
    } else {
      ans = ((ans) > (i - ans2) ? (ans) : (i - ans2));
    }
  }
  ans2 = 0;
  for (i = 1; i <= N; i++) {
    if (st[i] == 'a') {
      qu2.push(i);
      if (qu2.size() > K) {
        ans2 = qu2.front();
        qu2.pop();
        ans = ((ans) > (i - ans2) ? (ans) : (i - ans2));
      } else {
        ans = ((ans) > (i - ans2) ? (ans) : (i - ans2));
      }
    } else {
      ans = ((ans) > (i - ans2) ? (ans) : (i - ans2));
    }
  }
  cout << ans;
  return 0;
}
