#include <bits/stdc++.h>
using namespace std;
long long func(long long n) {
  if (n % 2 == 1) {
    return 1;
  } else {
    return n / 2;
  }
}
bool check(vector<long long> &prea, vector<long long> &preb, long long mid,
           long long n, long long k) {
  long long low = 0;
  long long upp = mid - 1;
  while (upp <= n - 1) {
    long long mini;
    if (low - 1 < 0) {
      mini = min(prea[upp], preb[upp]);
    } else {
      mini = min(prea[upp] - prea[low - 1], preb[upp] - preb[low - 1]);
    }
    if (mini <= k) {
      return true;
    }
    low++;
    upp++;
  }
  return false;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<long long> prea(n + 1, 0);
    vector<long long> preb(n + 1, 0);
    if (s[0] == 'a') {
      prea[0] = 1;
    } else {
      preb[0] = 1;
    }
    for (long long i = 1; i <= n; i++) {
      if (s[i] == 'a') {
        prea[i] = prea[i - 1] + 1;
        preb[i] = preb[i - 1];
      } else {
        preb[i] = preb[i - 1] + 1;
        prea[i] = prea[i - 1];
      }
    }
    long long l = 1;
    long long r = n;
    long long maxi = 0;
    while (l <= r) {
      long long mid = (l + r) / 2;
      bool ans = check(prea, preb, mid, n, k);
      if (ans) {
        l = mid + 1;
        maxi = max(maxi, mid);
      } else {
        r = mid - 1;
      }
    }
    cout << maxi << endl;
  }
}
