#include <bits/stdc++.h>
using namespace std;
const long long int lim = 100001;
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) {
      ans = ((ans % 1000000007) * (a % 1000000007)) % 1000000007;
    }
    a = ((a % 1000000007) * (a % 1000000007)) % 1000000007;
    b = b >> 1;
  }
  return ans;
}
long long int powe(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) {
      ans = a * ans;
    }
    a = a * a;
    b = b >> 1;
  }
  return ans;
}
long long int ncr(long long int n, long long int r) {
  if (r > n - r) {
    r = n - r;
  }
  long long int ans = 1;
  for (int i = 0; i < r; i++) {
    ans = ans * ((n - i) % 1000000007);
    ans = ans % 1000000007;
    ans = ans * power(i + 1, 1000000007 - 2);
    ans = ans % 1000000007;
  }
  return ans;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long int st = 0;
  long long int end = 0;
  map<char, long long int> mp;
  long long int ans = 0;
  while (st <= end && end < n) {
    if (s[end] == 'b') {
      if (mp['b'] < k) {
        mp['b']++;
        end++;
      } else if (st < end) {
        mp[s[st]]--;
        st++;
      } else {
        end++;
        st = end;
      }
    } else {
      mp[s[end]]++;
      end++;
    }
    ans = ((ans > end - st) ? (ans) : (end - st));
  }
  mp.clear();
  st = 0, end = 0;
  while (st <= end && end < n) {
    if (s[end] == 'a') {
      if (mp['a'] < k) {
        mp['a']++;
        end++;
      } else if (st < end) {
        mp[s[st]]--;
        st++;
      } else {
        end++;
        st = end;
      }
    } else {
      mp[s[end]]++;
      end++;
    }
    ans = ((ans > end - st) ? (ans) : (end - st));
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  while (t > 0) {
    solve();
    t--;
  }
}
