#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
bool check(long long mid, long long k, long long n, string s,
           vector<long long> &va, vector<long long> &vb) {
  long long i = 0;
  while (i <= n - mid) {
    long long change = 0, a = 0, b = a;
    a = va[i + mid] - va[i];
    b = vb[i + mid] - vb[i];
    change = min(a, b);
    if (change <= k) return false;
    i++;
  }
  return true;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long low = 0, high = n + 1, mid;
  vector<long long> va(n + 1, 0), vb(n + 1, 0);
  for (long long i = 1; i <= n; i++) {
    if (s[i - 1] == 'a') {
      va[i] = va[i - 1] + 1;
      vb[i] = vb[i - 1];
    } else {
      va[i] = va[i - 1];
      vb[i] = vb[i - 1] + 1;
    }
  }
  while (low < high) {
    mid = (low + high) / 2;
    if (check(mid, k, n, s, va, vb))
      high = mid;
    else
      low = mid + 1;
  }
  cout << low - 1 << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
