#include <bits/stdc++.h>
const long long MXN = 1e5 + 1;
const long long MNN = 1e3 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long OO = 1e9 + 500;
using namespace std;
int n, k, ans, pa[MXN], push_back[MXN];
string s;
bool check(int l, int r) {
  if (min(pa[r] - pa[l - 1], push_back[r] - push_back[l - 1]) <= k) {
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
  ;
  cin >> n >> k >> s;
  s = '#' + s;
  for (int i = 1; i <= n; i++) {
    pa[i] = pa[i - 1] + (s[i] == 'a' ? 1 : 0);
    push_back[i] = push_back[i - 1] + (s[i] == 'b' ? 1 : 0);
  }
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] != s[i]) {
      int l = i, r = n;
      while (r - l > 1) {
        int m = (r + l) / 2;
        if (check(i, m) == 1) {
          l = m;
        } else {
          r = m;
        }
      }
      int x = (check(i, r) == 1 ? r : l) - i + 1;
      ans = max(ans, x);
    }
  }
  cout << ans;
  return 0;
}
