High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.

Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?


-----Input-----

The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.

The second line contains the string, consisting of letters 'a' and 'b' only.


-----Output-----

Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.


-----Examples-----
Input
4 2
abba

Output
4

Input
8 1
aabaabaa

Output
5



-----Note-----

In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".

In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".

Source: codeforces | Difficulty: MEDIUM
Tags: String algorithms

Sorting

Amortized analysis

Dynamic programming


Solutions:
(n, k) = map(int, input().strip().split())
s = input()
maxi = 0
start = 0
last = 0
left = k
for i in range(n):
	if s[i] == 'a':
		last += 1
	elif left > 0:
		left -= 1
		last += 1
	else:
		while s[start] != 'b':
			start += 1
			last -= 1
		start += 1
	maxi = max(last, maxi)
start = 0
last = 0
left = k
for i in range(n):
	if s[i] == 'b':
		last += 1
	elif left > 0:
		left -= 1
		last += 1
	else:
		while s[start] != 'a':
			start += 1
			last -= 1
		start += 1
	maxi = max(last, maxi)
print(maxi)


I = lambda : int(input())
IL = lambda : list(map(int, input().split()))
(n, k) = IL()
s = input()
l1 = list(map(len, s.split('a')))
l2 = list(map(len, s.split('b')))
ms = cs = sum(l1[:k + 1]) + len(l1[:k + 1]) - 1
for i in range(len(l1) - k - 1):
	cs += l1[i + k + 1] - l1[i]
	ms = max(ms, cs)
cs = sum(l2[:k + 1]) + len(l2[:k + 1]) - 1
ms = max(ms, cs)
for i in range(len(l2) - k - 1):
	cs += l2[i + k + 1] - l2[i]
	ms = max(ms, cs)
print(ms)


entrada = input().split()
n = int(entrada[0])
k = int(entrada[1])
s = input()
esquerda = 0
tamanho = 0
ct = [0] * 2
for direita in range(0, n):
	ct[ord(s[direita]) - ord('a')] += 1
	if ct[0] <= k or ct[1] <= k:
		temp = direita - esquerda + 1
		tamanho = tamanho if tamanho > temp else temp
	else:
		ct[ord(s[esquerda]) - ord('a')] -= 1
		esquerda += 1
print(tamanho)


(n, k) = map(int, input().split())
s = input()

def solve(x, y):
	(res, j, t) = (0, 0, k)
	for i in range(n):
		if j < i:
			j = i
			t = k
		while j < n and (s[j] == x or (s[j] == y and t > 0)):
			t -= int(s[j] == y)
			j += 1
		res = max(res, j - i)
		t += int(s[i] == y)
	return res
print(max(solve('a', 'b'), solve('b', 'a')))


(n, k) = map(int, input().split())
s = input()
(a, b, l) = (0, 0, 0)
ans = 0
for r in s:
	if r == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) > k:
		if s[l] == 'a':
			a -= 1
		else:
			b -= 1
		l += 1
	else:
		ans += 1
print(ans)


from sys import *
inp = lambda : stdin.readline()

def solve(x, s, n, k):
	(ans, r, bal) = (0, 0, 0)
	for l in range(n):
		while r < n and (s[r] == x or bal < k):
			if s[r] != x:
				bal += 1
			r += 1
		ans = max(ans, r - l)
		if s[l] != x:
			bal -= 1
	return ans

def main():
	(n, k) = map(int, inp().split())
	s = inp()
	print(max(solve('a', s, n, k), solve('b', s, n, k)))
main()


import sys, math
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
import collections as col
import math

def solve():
	(N, K) = getInts()
	S = [' '] + listStr()
	A_count = [0]
	B_count = [0]
	curr_A = curr_B = 0
	AK_ind = N
	BK_ind = N
	for n in range(1, N + 1):
		if S[n] == 'a':
			curr_A += 1
			if curr_A == K + 1 and AK_ind == N:
				AK_ind = n - 1
		else:
			curr_B += 1
			if curr_B == K + 1 and BK_ind == N:
				BK_ind = n - 1
		A_count.append(curr_A)
		B_count.append(curr_B)
	if max(AK_ind, BK_ind) == N:
		return N
	best_A = BK_ind
	for n in range(2, N + 1):
		if S[n - 1] == 'a':
			continue
		BK_ind += 1
		while BK_ind < N and S[BK_ind + 1] == 'a':
			BK_ind += 1
		best_A = max(best_A, BK_ind - n + 1)
		if BK_ind == N:
			break
	best_B = AK_ind
	for n in range(2, N + 1):
		if S[n - 1] == 'b':
			continue
		AK_ind += 1
		while AK_ind < N and S[AK_ind + 1] == 'b':
			AK_ind += 1
		best_B = max(best_B, AK_ind - n + 1)
		if AK_ind == N:
			break
	return max(best_A, best_B)
print(solve())


a = [int(x) for x in input().split()]
b = 0
c = 0
asum = 0
bsum = 0
sorozat = input()
helyek = []
helyek.append(-1)
for x in range(len(sorozat)):
	if sorozat[x] == 'a':
		asum += 1
		helyek.append(x)
helyek.append(a[0])
if asum <= a[1]:
	c = a[0]
else:
	for x in range(len(helyek)):
		if b + a[1] + 1 < len(helyek) and helyek[b + a[1] + 1] - helyek[b] - 1 > c:
			c = helyek[b + a[1] + 1] - helyek[b] - 1
		b = b + 1
b2 = 0
c2 = 0
helyek2 = []
helyek2.append(-1)
for x in range(len(sorozat)):
	if sorozat[x] == 'b':
		bsum += 1
		helyek2.append(x)
helyek2.append(a[0])
if bsum <= a[1]:
	c2 = a[0]
else:
	for x in range(len(helyek2)):
		if b2 + a[1] + 1 < len(helyek2) and helyek2[b2 + a[1] + 1] - helyek2[b2] - 1 > c2:
			c2 = helyek2[b2 + a[1] + 1] - helyek2[b2] - 1
		b2 = b2 + 1
if c > c2:
	c2 = c
print(c2)


(n, k) = map(int, input().strip().split())
s = input().strip()
max_len = 0

def fun(letter):
	global max_len
	curr_len = swaps = l = 0
	r = -1
	while r < n - 1:
		r += 1
		curr_len += 1
		c = s[r]
		if c == letter:
			swaps += 1
		while swaps > k:
			curr_len -= 1
			posito = s[l]
			if posito == letter:
				swaps -= 1
			l += 1
		max_len = max(max_len, curr_len)
fun('a')
fun('b')
print(max_len)


def maxim(s, ch, k):
	res = 0
	maxi = 0
	c = 0
	start = 0
	kc = 0
	for i in range(0, len(s)):
		if s[i] == ch:
			c += 1
		else:
			kc += 1
			c += 1
		maxi = max(maxi, i - start) if kc > k else max(maxi, i - start + 1)
		while kc > k:
			if s[start] != ch:
				kc -= 1
				c -= 1
			start += 1
			maxi = max(maxi, i - start)
	return maxi
(n, k) = map(int, input().split())
s = input()
print(max(maxim(s, 'a', k), maxim(s, 'b', k)))


(n, k) = map(int, input().split())
s = input()
a = 0
b = 0
ans = 0
x = 0
for i in range(n):
	if s[i] == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) <= k:
		ans = max(ans, a + b)
	else:
		if s[x] == 'a':
			a -= 1
		else:
			b -= 1
		x += 1
print(ans)


(n, k) = list(map(int, input().split()))
s = input()
res = 0
count_a = 0
count_b = 0
left = 0
right = 0
while True:
	if s[right] == 'a':
		count_a += 1
	else:
		count_b += 1
	if count_a <= k or count_b <= k:
		if right - left + 1 > res:
			res = right - left + 1
	else:
		if s[left] == 'a':
			count_a -= 1
		else:
			count_b -= 1
		left += 1
	right += 1
	if n - left < res or right == n:
		break
print(res)


(n, k) = map(int, input().split())
s = input()
res = 1
i = -1
j = 0
cur = 0
while i < j <= n:
	if j == n and i == n - 1:
		break
	while cur <= k and j < n:
		if cur == k and s[j] == 'b':
			break
		else:
			cur += s[j] == 'b'
			j += 1
	res = max(res, j - i - 1)
	if k > 0:
		if cur < k and i < j - 1:
			i += 1
			cur -= s[i] == 'b'
		while cur == k and i < j - 1:
			i += 1
			cur -= s[i] == 'b'
	else:
		i = j
		j = i + 1
res = max(res, j - i - 1)
i = -1
j = 0
cur = 0
while i < j <= n:
	if j == n and i == n - 1:
		break
	while cur <= k and j < n:
		if cur == k and s[j] == 'a':
			break
		else:
			cur += s[j] == 'a'
			j += 1
	res = max(res, j - i - 1)
	if k > 0:
		if cur < k and i < j - 1:
			i += 1
			cur -= s[i] == 'a'
		while cur == k and i < j - 1:
			i += 1
			cur -= s[i] == 'a'
	else:
		i = j
		j = i + 1
res = max(res, j - i - 1)
print(res)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
s = [i for i in input() if i != '\n']

def checker(m):
	l = [0, 0]
	for i in range(m):
		l[ord(s[i]) - 97] += 1
	if min(l) <= k:
		return True
	for i in range(m, len(s)):
		l[ord(s[i - m]) - 97] -= 1
		l[ord(s[i]) - 97] += 1
		if min(l) <= k:
			return True
	return False
beg = 1
last = len(s)
while beg < last:
	mid = beg + (last - beg + 1) // 2
	ok = checker(mid)
	if ok:
		beg = mid
	else:
		last = mid - 1
print(beg)


(n, k) = map(int, input().split())
a = input()
ac = 0
bc = 0
ans = -1
s = 0
e = 0
if k == 0:
	while e < n:
		ac = 0
		if a[e] == 'a':
			while e < n and a[e] == 'a':
				ac += 1
				e += 1
		else:
			while e < n and a[e] == 'b':
				ac += 1
				e += 1
		ans = max(ans, ac)
else:
	while e < n:
		if a[e] == 'a':
			ac += 1
		else:
			bc += 1
		while min(ac, bc) > k:
			s += 1
			if a[s - 1] == 'a':
				ac -= 1
			else:
				bc -= 1
		ans = max(ans, e - s + 1)
		e += 1
print(ans)


(n, m) = input().split(' ')
(n, m) = (int(n), int(m))
ans = 0
s = input()
for i in range(2):
	(left, used) = (0, 0)
	for right in range(n):
		if ord(s[right]) != ord('a') + i:
			used += 1
		while used > m:
			if ord(s[left]) != ord('a') + i:
				used -= 1
			left += 1
		ans = max(ans, right - left + 1)
print(ans)


from collections import defaultdict
(n, k) = [int(i) for i in input().split()]
s = input()
Dict = defaultdict(int)
start = 0
end = 0
ans = 0
while end < n:
	Dict[s[end]] += 1
	while k - min(Dict['a'], Dict['b']) < 0:
		Dict[s[start]] -= 1
		start += 1
	ans = max(ans, end - start + 1)
	end += 1
print(ans)


def solve(k, s, c):
	p = [-1, len(s)]
	for i in range(len(s)):
		if s[i] == c:
			p += [i]
	p.sort()
	n = len(p)
	if n - k - 1 <= 0:
		return len(s)
	m = 0
	for i in range(n - k - 1):
		m = max(m, p[i + k + 1] - p[i])
	return m - 1
(n, k) = list(map(int, input().split()))
s = input()
print(max(solve(k, s, 'a'), solve(k, s, 'b')))


def main():
	(n, k) = liee()
	s = input()
	(l, ans, h) = (1, 0, n)
	while l <= h:
		m = (l + h) // 2
		if fun(m, n, s, k):
			(ans, l) = (m, m + 1)
		else:
			h = m - 1
	print(ans)

def fun(m, n, s, k):
	(a, b) = (s[0:m].count('a'), s[0:m].count('b'))
	if max(a, b) + k >= m:
		return 1
	for i in range(m, n):
		if s[i - m] == 'a':
			a -= 1
		else:
			b -= 1
		if s[i] == 'a':
			a += 1
		else:
			b += 1
		if max(a, b) + k >= m:
			return 1
	return 0

def fun2(s):
	(cnt, num) = (0, s.count('0'))
	for i in s[1:]:
		if i == '1':
			cnt += 1
		elif num == 1:
			cnt += 1
			break
		else:
			break
	return cnt
from sys import *
import inspect
import re
from math import *
import threading
from collections import *
from pprint import pprint as pp
mod = 998244353
MAX = 10 ** 5

def lie():
	return int(input())

def liee():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def deb(p):
	for line in inspect.getframeinfo(inspect.currentframe().f_back)[3]:
		m = re.search('\\bdeb\\s*\\(\\s*([A-Za-z_][A-Za-z0-9_]*)\\s*\\)', line)
		print('%s %d' % (m.group(1), p))

def vector(size, val=0):
	vec = [val for i in range(size)]
	return vec

def matrix(rowNum, colNum, val=0):
	mat = []
	for i in range(rowNum):
		collumn = [val for j in range(colNum)]
		mat.append(collumn)
	return mat

def dmain():
	setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
dmain()


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def possible(x):
	start = 0
	for i in range(x, n + 1):
		if countA[i] - countA[start] <= k:
			return True
		if countB[i] - countB[start] <= k:
			return True
		start += 1
	return False
(n, k) = value()
s = input()
countB = [0]
countA = [0]
a = 0
b = 0
for i in range(n):
	if s[i] == 'a':
		a += 1
	else:
		b += 1
	countA.append(a)
	countB.append(b)
low = 0
high = n
while low <= high:
	mid = (low + high) // 2
	if possible(mid):
		ans = mid
		low = mid + 1
	else:
		high = mid - 1
print(ans)


s = input().split()
(n, k) = (int(s[0]), int(s[1]))
s = input()
ans = 0
k1 = k
i1 = -1
i2 = 0
while i1 < n - 1:
	i1 += 1
	if s[i1] == 'b':
		if k1 > 0:
			k1 -= 1
		else:
			while s[i2] != 'b':
				i2 += 1
			i2 += 1
	if ans < i1 - i2:
		ans = i1 - i2
k1 = k
i1 = -1
i2 = 0
while i1 < n - 1:
	i1 += 1
	if s[i1] == 'a':
		if k1 > 0:
			k1 -= 1
		else:
			while s[i2] != 'a':
				i2 += 1
			i2 += 1
	if ans < i1 - i2:
		ans = i1 - i2
print(ans + 1)


(n, k) = map(int, input().split())
a = input().strip()
length = 0
lo = 0
cost = 0
for hi in range(n):
	if a[hi] == 'b':
		cost += 1
	if cost > k:
		while lo <= hi and cost > k:
			if a[lo] == 'b':
				cost -= 1
			lo += 1
	length = max(length, hi - lo + 1)
lo = 0
cost = 0
for hi in range(n):
	if a[hi] == 'a':
		cost += 1
	if cost > k:
		while lo <= hi and cost > k:
			if a[lo] == 'a':
				cost -= 1
			lo += 1
	length = max(length, hi - lo + 1)
print(length)


(n, k) = map(int, input().split())
s = input()
a = [0] * len(s)
b = [0] * len(s)
for i in range(len(s)):
	if s[i] == 'a':
		a[i] += 1
	else:
		b[i] += 1
	if i > 0:
		a[i] += a[i - 1]
		b[i] += b[i - 1]
ans = 0
for i in range(len(s)):
	lo = 0
	hi = len(s) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		count = a[mid] - (a[i - 1] if i > 0 else 0)
		if count > k:
			hi = mid - 1
		else:
			lo = mid + 1
	ans = max(ans, hi - i + 1)
	lo = 0
	hi = len(s) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		count = b[mid] - (b[i - 1] if i > 0 else 0)
		if count > k:
			hi = mid - 1
		else:
			lo = mid + 1
	ans = max(ans, hi - i + 1)
print(ans)


def find_max(n, m, t, char='a'):
	l = 0
	r = 0
	count = 0
	ans = 0
	num = 0
	while r < n:
		if t[r] == char:
			count += 1
			r += 1
		elif t[r] != char and num < m:
			count += 1
			r += 1
			num += 1
		elif t[r] != char and num >= m:
			ans = max(ans, count)
			if l == -1:
				l += 1
			else:
				if t[l] != char:
					num -= 1
				count -= 1
				l += 1
		ans = max(count, ans)
	return ans
(n, m) = map(int, input().split())
t = input()
ans = max(find_max(n, m, t), find_max(n, m, t, 'b'))
print(ans)


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()

def fun(l, k):
	length = len(l)
	c = 1
	for i in range(1, length):
		c = max(l[min(i + k, length - 1)] - l[i - 1] - 1, c)
	return c

def solve():
	(n, k) = I()
	s = I1().strip()
	a = [-1]
	b = [-1]
	for i in range(n):
		if s[i] == 'a':
			a.append(i)
		else:
			b.append(i)
	a.append(n)
	b.append(n)
	print(max(fun(a, k), fun(b, k)))
solve()


import sys
input = sys.stdin.readline

def prog():
	(n, k) = map(int, input().split())
	string = input().strip()
	if k == 0:
		print(max(max(map(len, string.split('a'))), max(map(len, string.split('b')))))
	else:
		ka = k
		for i in range(n):
			if string[i] == 'b':
				ka -= 1
				if ka == 0:
					break
		stop = False
		for i in range(i + 1, n):
			if string[i] != 'a':
				stop = True
				break
		i = i - stop
		maxa = i + 1
		curr_total = i + 1
		curr_start = string.find('b')
		curr_end = i
		while curr_end < n - 1:
			if string[curr_start] == 'b':
				lost = 0
				i = curr_start - 1
				while string[i] == 'a' and i >= 0:
					lost += 1
					i -= 1
				i = curr_end + 1
				added = 0
				not_changed = True
				while i < n and (string[i] == 'a' or not_changed):
					if string[i] == 'b':
						not_changed = False
					added += 1
					i += 1
				curr_total = curr_total - lost - 1 + added
				maxa = max(curr_total, maxa)
				curr_start += 1
				curr_end = curr_end + added
			else:
				while string[curr_start] != 'b':
					curr_start += 1
		kb = k
		for i in range(n):
			if string[i] == 'a':
				kb -= 1
				if kb == 0:
					break
		stop = False
		for i in range(i + 1, n):
			if string[i] != 'b':
				stop = True
				break
		i = i - stop
		maxb = i + 1
		curr_total = i + 1
		curr_start = string.find('a')
		curr_end = i
		while curr_end < n - 1:
			if string[curr_start] == 'a':
				lost = 0
				i = curr_start - 1
				while string[i] == 'b' and i >= 0:
					lost += 1
					i -= 1
				i = curr_end + 1
				added = 0
				not_changed = True
				while i < n and (string[i] == 'b' or not_changed):
					if string[i] == 'a':
						not_changed = False
					added += 1
					i += 1
				curr_total = curr_total - lost - 1 + added
				maxb = max(maxb, curr_total)
				curr_start += 1
				curr_end = curr_end + added
			else:
				while string[curr_start] != 'a':
					curr_start += 1
		print(max(maxa, maxb))
prog()


def executa(n, k, letra, s):
	r = 0
	tk = k
	p = 0
	for i in range(n):
		while r < n and tk >= 0:
			if a[r] == letra:
				if tk == 0:
					break
				tk -= 1
			r += 1
			p += 1
		s = max(s, p)
		p -= 1
		if a[i] == letra:
			tk += 1
		if r == n:
			break
	return s
entrada = input()
entrada_str = list(entrada.split(' '))
entrada_int = list(map(int, entrada_str))
n = entrada_int[0]
k = entrada_int[1]
a = input()
soma = executa(n, k, 'b', 0)
soma = executa(n, k, 'a', soma)
print(soma)


(n, k) = map(int, input().split())
s = input()
l = 0
r = 0
d = {}
v = -1
ans = 0
while l < n:
	while r < n:
		if v != r:
			d[s[r]] = d.get(s[r], 0) + 1
		if len(d) > 2:
			d[s[r]] -= 1
			if d[s[r]] == 0:
				d.pop(s[r])
			break
		if d:
			m = min(d.values())
			if m > k and len(d) == 2:
				break
		r += 1
	ans = max(ans, r - l)
	v = r
	d[s[l]] -= 1
	if d[s[l]] == 0:
		d.pop(s[l])
	l += 1
print(ans)


def solve(string, k):
	n = len(string)
	ans = 0
	left = 0
	cur = 0
	for i in range(n):
		cur += string[i] == 'b'
		while cur > k:
			cur -= string[left] == 'b'
			left += 1
		ans = max(ans, i - left + 1)
	return ans
(n, k) = map(int, input().split())
string = list(input())
ans = solve(string, k)
for i in range(n):
	string[i] = 'b' if string[i] == 'a' else 'a'
ans = max(ans, solve(string, k))
print(ans)


(n, k) = map(int, input().split())
s = input()
(a, b) = (0, 0)
j = 0
ans = 0
for i in s:
	if i == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) > k:
		if s[j] == 'a':
			a -= 1
		else:
			b -= 1
		j += 1
	else:
		ans += 1
print(ans)


from collections import deque
(n, k) = (int(x) for x in input().split())
s = input()

def count(c):
	(l, r) = (0, 0)
	q = deque()
	mx = 1
	while r < n:
		if s[r] != c:
			q.append(r)
			if len(q) > k:
				l = q.popleft() + 1
		mx = max(mx, r - l + 1)
		r += 1
	return mx
print(max(count('a'), count('b')))


import math
(n, m) = map(int, input().split())
s = input()
j = 0
ans = 0
d = {'a': 0, 'b': 0}
for i in s:
	d[i] += 1
	if min(d.values()) > m:
		d[s[j]] -= 1
		j += 1
	else:
		ans += 1
print(ans)


from sys import stdin, stdout
import math
input = stdin.readline

def check(s, c, n, k):
	(j, cnt, ans) = (0, 0, 0)
	for i in range(n):
		cnt += int(s[i] == c)
		while j <= i and cnt > k:
			cnt -= int(s[j] == c)
			j += 1
		ans = max(ans, i - j + 1)
	return ans

def solve():
	(n, k) = map(int, input().split())
	s = input()
	print(max(check(s, 'a', n, k), check(s, 'b', n, k)))
tt = 1
for __ in range(tt):
	solve()


def checkmax(s, ch, k):
	count = 0
	ptr1 = 0
	maxx_length = 0
	temp = 0
	for i in range(len(s)):
		temp += s[i] != ch
		while temp > k:
			temp -= s[ptr1] != ch
			ptr1 += 1
		temp_length = i - (ptr1 - 1)
		maxx_length = max(temp_length, maxx_length)
	return maxx_length
(n, k) = (int(i) for i in input().split())
s = input()
print(max(checkmax(s, 'a', k), checkmax(s, 'b', k)))


(n, k) = map(int, input().split())
s = input()
i = 0
j = 0
a = 0
b = 0
ans = 0
while j < n:
	if s[j] == 'a':
		a += 1
	if s[j] == 'b':
		b += 1
	if a <= k or b <= k:
		ans = max(ans, a + b)
	else:
		if s[i] == 'a':
			a -= 1
		if s[i] == 'b':
			b -= 1
		i += 1
	j += 1
print(ans)


import sys
import math
import collections
from pprint import pprint
mod = 1000000007

def vector(size, val=0):
	vec = [val for i in range(size)]
	return vec

def matrix(rowNum, colNum, val=0):
	mat = []
	for i in range(rowNum):
		collumn = [val for j in range(colNum)]
		mat.append(collumn)
	return mat

def fun(m):
	cnt1 = s[0:m].count('a')
	cnt2 = s[0:m].count('b')
	if max(cnt1, cnt2) + k >= m:
		return 1
	for i in range(m, len(s)):
		if s[i - m] == 'a':
			cnt1 -= 1
		else:
			cnt2 -= 1
		if s[i] == 'a':
			cnt1 += 1
		else:
			cnt2 += 1
		if max(cnt1, cnt2) + k >= m:
			return 1
	return 0
(n, k) = map(int, input().split())
s = input()
l = 1
h = n
ans = 0
while l <= h:
	m = (l + h) // 2
	if fun(m):
		ans = m
		l = m + 1
	else:
		h = m - 1
print(ans)


(n, k) = map(int, input().split())
s = input()
ansa = 0
a = 0
b = 0
starta = 0
for i in range(0, n):
	if s[i] == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) > k:
		if s[starta] == 'a':
			a -= 1
		else:
			b -= 1
		starta += 1
	else:
		ansa += 1
print(ansa)


def get_best(s, n, k, c):
	l = 0
	r = 0
	curr_k = k
	best = 0
	while l < n and r < n:
		if s[r] == c:
			r += 1
		elif curr_k > 0:
			curr_k -= 1
			r += 1
		else:
			if s[l] != c:
				curr_k += 1
			l += 1
		best = max(best, r - l + 1)
	return best - 1
(n, k) = map(int, input().split())
s = input()
best_a = get_best(s, n, k, 'a')
best_b = get_best(s, n, k, 'b')
print(max(best_a, best_b))


(n, k) = map(int, input().split())
s = [*input()]
(a, b) = ([0], [0])
for i in s:
	if i == 'a':
		a.append(a[-1] + 1)
		b.append(b[-1])
	else:
		a.append(a[-1])
		b.append(b[-1] + 1)

def check(m):
	for i in range(m, n + 1):
		if a[i] - a[i - m] <= k:
			return True
		if b[i] - b[i - m] <= k:
			return True
	return False
i = 0
j = n
while i <= j:
	m = (i + j) // 2
	if check(m):
		i = m + 1
	else:
		j = m - 1
print(j)


(n, k) = map(int, input().split())
s = input()

def f(a):
	if len(a) <= k:
		return n
	a = [-1] + a + [n]
	return max((a[i] - a[i - k - 1] - 1 for i in range(k + 1, len(a))))
print(max(f([i for (i, ch) in enumerate(s) if ch == 'a']), f([i for (i, ch) in enumerate(s) if ch == 'b'])))


from sys import stdin

def scan(K, line, x):
	start = 0
	length = len(line)
	max_t = 0
	(cx, cnx) = (0, 0)
	for end in range(length):
		char = line[end]
		if char == x:
			cx += 1
		else:
			cnx += 1
		if cnx > K:
			max_t = max(max_t, cx + cnx - 1)
			while line[start] == x:
				start += 1
				cx -= 1
			start += 1
			cnx -= 1
	max_t = max(max_t, cx + cnx)
	return max_t

def solve(K, line):
	result = scan(K, line, 'a')
	result2 = scan(K, line, 'b')
	print(max(result, result2))

def parse():
	line = stdin.readline().split()
	(N, K) = map(int, line)
	line = stdin.readline().strip()
	solve(K, line)
parse()


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
s = input()
a = b = j = x = 0
for i in s:
	if i == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) > k:
		if s[j] == 'a':
			a -= 1
		else:
			b -= 1
		j += 1
	else:
		x += 1
print(x)


num = input()
(n, k) = num.split()
n = int(n)
k = int(k)
string = input()
count_a = 0
count_b = 0

def check(ch):
	i = 0
	j = 0
	count = 0
	answer = 0
	for i in range(n):
		if string[i] == ch:
			count += 1
		if count > k:
			while count > k:
				if string[j] == ch:
					count -= 1
				j += 1
		answer = max(answer, i - j + 1)
	return answer
max_a = check('a')
max_b = check('b')
print(max(max_a, max_b))


(n, k) = map(int, input().split())
s = input().rstrip()
if 'a' not in s or 'b' not in s:
	print(n)
	exit()
a = [0]
b = [0]
for ch in s:
	a.append(a[-1] + (ch == 'a'))
	b.append(b[-1] + (ch == 'b'))

def maxSize(a):
	ret = 0
	first = [-1] * n
	for (i, val) in enumerate(a):
		if first[val] == -1:
			first[val] = i
		if val <= k:
			ret = max(ret, i)
		elif first[val - k] != -1:
			ret = max(ret, i - first[val - k])
	return ret
print(max(maxSize(a), maxSize(b)))


def solve(middle, s, k):
	aa = 0
	bb = 0
	f = 0
	for i in range(0, middle):
		if s[i] == 'a':
			aa += 1
		else:
			bb += 1
	if min(aa, bb) <= k:
		f = 1
	for i in range(0, len(s) - middle):
		if s[i] == 'a':
			aa -= 1
		else:
			bb -= 1
		if s[i + middle] == 'a':
			aa += 1
		else:
			bb += 1
		if min(aa, bb) <= k:
			f = 1
	return f
(n, k) = map(int, input().split())
s = str(input())
left = 1
right = n + 1
while left + 1 != right:
	middle = (left + right) // 2
	if solve(middle, s, k):
		left = middle
	else:
		right = middle
print(left)


def func(A, n, k, ch):
	i = 0
	j = 0
	cnt = 0
	maxlen = 1
	while i < n:
		if A[i] != ch:
			cnt += 1
		while cnt > k:
			if A[j] != ch:
				cnt -= 1
			j += 1
		maxlen = max(maxlen, i - j + 1)
		i = i + 1
	return maxlen
(n, k) = map(int, input().split())
A = str(input())
m1 = func(A, n, k, 'a')
m2 = func(A, n, k, 'b')
ans = max(m1, m2)
print(ans)


def main():
	(n, k) = [int(x) for x in input().split()]
	s = input()
	a = s[0] == 'a' and 1 or 0
	b = s[0] == 'b' and 1 or 0
	i = 0
	j = 0
	res = 1
	while j < n - 1:
		aj = 0
		bj = 0
		if s[j + 1] == 'a':
			aj += 1
		else:
			bj += 1
		if min(a + aj, b + bj) <= k:
			j += 1
			a += aj
			b += bj
			res = max(res, j - i + 1)
		else:
			if s[i] == 'a':
				a -= 1
			else:
				b -= 1
			i += 1
	print(res)
main()


(a, b) = map(int, input().split())
d = input()
e = 1
f = a + 1
a1 = [0]
a2 = [0]
for i in range(a):
	if d[i] == 'a':
		a1.append(a1[-1] + 1)
		a2.append(a2[-1])
	else:
		a2.append(a2[-1] + 1)
		a1.append(a1[-1])

def s1(i, j):
	return a1[j + 1] - a1[i]

def s2(i, j):
	return a2[j + 1] - a2[i]

def q(n):
	for i in range(0, a - n + 1):
		j = i + n - 1
		x1 = s1(i, j)
		x2 = s2(i, j)
		if x1 <= b or x2 <= b:
			return True
	return False
while e + 1 < f:
	g = (e + f) // 2
	if q(g):
		e = g
	else:
		f = g
if e == a - 1:
	v = d.count('a')
	if v <= b or a - v <= b:
		print(a)
	else:
		print(e)
else:
	print(e)


(n, k) = map(int, input().split())
s = input()
ca = cb = 0
q = []
ans = 0
l = 0
r = 0
for i in s:
	if i == 'a':
		ca += 1
	else:
		cb += 1
	r += 1
	q.append(i)
	while l <= r and min(ca, cb) > k:
		if q[l] == 'a':
			ca -= 1
		else:
			cb -= 1
		l += 1
	ans = max(ans, r - l)
print(ans)


from collections import deque
(n, k) = map(int, input().split())
s = input()
ca = cb = 0
q = deque()
ans = 0
for i in s:
	if i == 'a':
		ca += 1
	else:
		cb += 1
	q.append(i)
	while q and min(ca, cb) > k:
		if q[0] == 'a':
			ca -= 1
		else:
			cb -= 1
		q.popleft()
	ans = max(ans, len(q))
print(ans)


(n, k) = map(int, input().split())
s = input()
j = 0
c = 0
ans = 0
for i in range(n):
	if s[i] == 'a':
		c += 1
	while j < n and c > k:
		if s[j] == 'a':
			c -= 1
		j += 1
	ans = max(ans, i - j + 1)
j = 0
c = 0
for i in range(n):
	if s[i] == 'b':
		c += 1
	while j < n and c > k:
		if s[j] == 'b':
			c -= 1
		j += 1
	ans = max(ans, i - j + 1)
print(ans)


(n, k) = map(int, input().split())
a = list(input())
i = 0
j = 0
ans = 1
ca = cb = 0
if a[j] == 'a':
	ca += 1
else:
	cb += 1
while j < n and i < n:
	if min(ca, cb) <= k and j < n - 1:
		j += 1
		if a[j] == 'a':
			ca += 1
		else:
			cb += 1
	else:
		if a[i] == 'a':
			ca -= 1
		else:
			cb -= 1
		i += 1
	if min(ca, cb) <= k:
		ans = max(ca + cb, ans)
print(ans)


(n, k) = map(int, input().split())
s = input()
k1 = k
k2 = k
a = b = ans = 0
for i in range(n):
	if s[i] == 'b':
		k1 -= 1
	else:
		k2 -= 1
	while k1 < 0:
		if s[a] == 'b':
			k1 += 1
		a += 1
	while k2 < 0:
		if s[b] == 'a':
			k2 += 1
		b += 1
	ans = max(ans, i - a + 1, i - b + 1)
print(ans)


(n, k) = map(int, input().split())
s = input()
l = 0
r = 0
ch = 0
maxa = 0
if k == 0:
	maxa = 1
	count = 1
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			count += 1
		else:
			maxa = max(maxa, count)
			count = 1
	maxa = max(maxa, count)
	print(maxa)
	exit()
while l <= r and r < len(s) and (ch <= k):
	if s[r] == 'a':
		r += 1
		maxa = max(r - l, maxa)
	elif ch < k:
		ch += 1
		r += 1
	else:
		maxa = max(r - l, maxa)
		if s[l] == 'a':
			l += 1
		else:
			l += 1
			ch = ch - 1
maxa = max(maxa, r - l)
l = 0
r = 0
ch = 0
while l <= r and r < len(s) and (ch <= k):
	if s[r] == 'b':
		r += 1
		maxa = max(r - l, maxa)
	elif ch < k:
		ch += 1
		r += 1
	else:
		maxa = max(r - l, maxa)
		if s[l] == 'b':
			l += 1
		else:
			l += 1
			ch = ch - 1
maxa = max(maxa, r - l)
print(maxa)


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime

def primefactors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return fac

def factors(n):
	fac = set()
	fac.add(1)
	fac.add(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x

def good(mid, a, k):
	for i in range(0, len(a) - mid):
		if a[i + mid] - a[i] + k >= mid:
			return True
	return False
(n, k) = map(int, input().split())
s = input()
ans1 = []
ans2 = []
for i in range(0, len(s)):
	if s[i] == 'a':
		ans1.append(1)
		ans2.append(0)
	else:
		ans1.append(0)
		ans2.append(1)
a1 = [0] + list(accumulate(ans1))
a2 = [0] + list(accumulate(ans2))
l = 0
r = len(s)
fans = 1
fans2 = 1
while l <= r:
	mid = (l + r) // 2
	if good(mid, a1, k) == True:
		l = mid + 1
		fans = mid
	else:
		r = mid - 1
l = 0
r = len(s)
while l <= r:
	mid = (l + r) // 2
	if good(mid, a2, k) == True:
		l = mid + 1
		fans2 = mid
	else:
		r = mid - 1
print(max(fans, fans2))


(n, k) = map(int, input().split())
s = input()
res = 1
p1 = 0
p2 = 0
ck = 0
while p2 < n and p1 < n:
	if s[p2] == 'b' and ck < k or s[p2] == 'a':
		if s[p2] == 'b':
			ck += 1
		p2 += 1
		l = p2 - p1
		if l > res:
			res = l
	else:
		if s[p1] == 'b':
			ck -= 1
		p1 += 1
p1 = 0
p2 = 0
ck = 0
while p2 < n:
	if s[p2] == 'a' and ck < k or s[p2] == 'b':
		if s[p2] == 'a':
			ck += 1
		p2 += 1
		l = p2 - p1
		if l > res:
			res = l
	else:
		if s[p1] == 'a':
			ck -= 1
		p1 += 1
print(res)


(n, k) = map(int, input().split())
s = list(input())
ans = 0
m = [0, 0]
l = 0
for i in s:
	m[ord(i) - 97] += 1
	if min(m) > k:
		m[ord(s[l]) - 97] -= 1
		l += 1
	else:
		ans += 1
print(ans)


(n, k) = map(int, input().split())
string = str(input())
a = 0
b = 0
j = 0
d = 0
for i in range(n):
	if string[i] == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) > k:
		if string[j] == 'a':
			a -= 1
		else:
			b -= 1
		j += 1
	else:
		d += 1
print(d)


import sys, os, re, datetime
from collections import *
__cin_iter__ = None

def cin():
	try:
		global __cin_iter__
		if __cin_iter__ is None:
			__cin_iter__ = iter(input().split(' '))
		try:
			return next(__cin_iter__)
		except StopIteration:
			__cin_iter__ = iter(input().split(' '))
			return next(__cin_iter__)
	except EOFError:
		return None

def iin():
	return int(cin())

def fin():
	return float(cin())

def mat(v, *dims):

	def submat(i):
		if i == len(dims) - 1:
			return [v for _ in range(dims[-1])]
		return [submat(i + 1) for _ in range(dims[i])]
	return submat(0)

def iarr(n=0):
	return [int(v) for v in input().split(' ')]

def farr(n=0):
	return [float(v) for v in input().split(' ')]

def carr(n=0):
	return input()

def sarr(n=0):
	return [v for v in input().split(' ')]

def imat(n, m=0):
	return [iarr() for _ in range(n)]

def fmat(n, m=0):
	return [farr() for _ in range(n)]

def cmat(n, m=0):
	return [input() for _ in range(n)]

def smat(n, m=0):
	return [sarr() for _ in range(n)]

def lower_bound(a, lo, hi, v):
	while lo < hi:
		mid = lo + hi >> 1
		if a[mid] < v:
			lo = mid + 1
		else:
			hi = mid
	return lo
N = 100001
a = mat(0, N)
b = mat(0, N)
n = iin()
k = iin()
s = cin()
ans = k
b[0] = 1 if s[0] == 'b' else 0
a[0] = 1 if s[0] == 'a' else 0
for i in range(1, n):
	b[i] = b[i - 1] + (1 if s[i] == 'b' else 0)
	a[i] = a[i - 1] + (1 if s[i] == 'a' else 0)
for i in range(k, n):
	v = b[i] - k
	if v > 0:
		ans = max(ans, i - lower_bound(b, 0, i + 1, v))
	else:
		ans = max(ans, i + 1)
	v = a[i] - k
	if v > 0:
		ans = max(ans, i - lower_bound(a, 0, i + 1, v))
	else:
		ans = max(ans, i + 1)
print(ans)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(n, k) = int_array()
string = input().strip()
ans = 0
for char in 'ab':
	currChanges = 0
	pointerLeft = 0
	pointerRight = -1
	currLength = 0
	while pointerRight < n - 1:
		pointerRight += 1
		currLength += 1
		c = string[pointerRight]
		if c == char:
			currChanges += 1
		while currChanges > k:
			currLength -= 1
			if string[pointerLeft] == char:
				currChanges -= 1
			pointerLeft += 1
		ans = max(ans, currLength)
print(ans)


(n, k) = map(int, input().split())
s = list(input())

def isPossible(x):
	count_a = 0
	count_b = 0
	for i in range(x):
		if s[i] == 'a':
			count_a += 1
		else:
			count_b += 1
	if max(count_a, count_b) + k >= x:
		return True
	for i in range(1, n - x + 1):
		if s[i - 1] == 'a':
			count_a -= 1
		else:
			count_b -= 1
		if s[x + i - 1] == 'a':
			count_a += 1
		else:
			count_b += 1
		if max(count_a, count_b) + k >= x:
			return True
	return False
l = 1
r = n
ans = 1
while l <= r:
	mid = (l + r) // 2
	if isPossible(mid):
		l = mid + 1
		ans = max(ans, mid)
	else:
		r = mid - 1
print(ans)


(n, k) = map(int, input().split())
s = input()
longest = 0
(left, right) = (0, 0)
currb = 1 if s[0] == 'b' else 0
while True:
	while right < n and currb <= k:
		right += 1
		if right < n and s[right] == 'b':
			currb += 1
	longest = max(longest, right - left)
	if s[left] == 'b':
		currb -= 1
	left += 1
	if left == n or right == n:
		break
(left, right) = (0, 0)
currb = 1 if s[0] == 'a' else 0
while True:
	while right < n and currb <= k:
		right += 1
		if right < n and s[right] == 'a':
			currb += 1
	longest = max(longest, right - left)
	if s[left] == 'a':
		currb -= 1
	left += 1
	if left == n or right == n:
		break
print(longest)


(n, k) = map(int, input().split())
lst = input()
left = 0
right = 0

def current_length(left, right, changes_left, letter):
	best_len = 0
	curr_changes = changes_left
	while right < n:
		if curr_changes == 0 and lst[right] != letter:
			if right - left > best_len:
				best_len = right - left
			while left < n:
				if lst[left] != letter:
					left += 1
					break
				left += 1
		elif lst[right] != letter:
			curr_changes -= 1
		right += 1
	if right - left > best_len:
		best_len = right - left
	return best_len
print(max(current_length(0, 0, k, 'a'), current_length(0, 0, k, 'b')))


(n, k) = map(int, input().split())
a = input()
r = 0
b = [ord(x) - ord('a') for x in a]
s = 0
ans = 0
for i in range(n):
	while r < n and (s + b[r] <= k or r + 1 - i - s - b[r] <= k):
		s += b[r]
		r += 1
	ans = max(ans, r - i)
	s -= b[i]
	if r == n:
		break
print(ans)


def max_substring(s, ch, n, k):
	(i, j) = (0, 0)
	cnt = 0
	best = 0
	while j < n:
		if s[j] == ch:
			cnt += 1
		if cnt > k:
			tmp = j - i
			if tmp > best:
				best = tmp
			while i < j and s[i] != ch:
				i += 1
			i += 1
			cnt -= 1
		j += 1
	tmp = j - i
	if tmp > best:
		best = tmp
	return n if cnt <= k and best == 0 else best
(n, k) = map(int, input().split())
s = input()
a = max_substring(s, 'a', n, k)
b = max_substring(s, 'b', n, k)
print(a if a > b else b)


def count(a, n, s, k):
	j = 0
	kk = 0
	ans = 0
	for i in range(n):
		if a[i] == s:
			kk += 1
		while kk > k:
			if a[j] == s:
				kk = kk - 1
			j += 1
		ans = max(ans, i - j + 1)
	return ans
(n, k) = [int(i) for i in input().split()]
a = list(input())
c = a.count('a')
d = a.count('b')
if d == 0 or d == k:
	print(n)
elif k == 0:
	print(max(count(a, n, 'a', k), count(a, n, 'b', k)))
elif d > c:
	print(count(a, n, 'a', k))
else:
	print(count(a, n, 'b', k))


(n, t) = map(int, input().split())
s = input()
l = 0
k = 0
ma = 0
for r in range(n):
	if s[r] == 'a':
		if r - l + 1 > ma:
			ma = r - l + 1
	else:
		while k >= t:
			if s[l] == 'b':
				k -= 1
			l += 1
		if r - l + 1 > ma:
			ma = r - l + 1
		k += 1
		k %= r - l + 2
l = 0
k = 0
for r in range(n):
	if s[r] == 'b':
		if r - l + 1 > ma:
			ma = r - l + 1
	else:
		while k >= t:
			if s[l] == 'a':
				k -= 1
			l += 1
		if r - l + 1 > ma:
			ma = r - l + 1
		k += 1
		k %= r - l + 2
print(ma)


(n, k) = map(int, input().split())
txt = list(input())
l = 0
r = 0
countA = 0
countB = 0
ans = 1
while r <= n - 1:
	if txt[r] == 'a':
		countA += 1
	else:
		countB += 1
	change = min(countA, countB)
	if change <= k:
		ans = max(r - l + 1, ans)
	else:
		if txt[l] == 'a':
			countA -= 1
		else:
			countB -= 1
		l += 1
		change = min(countA, countB)
		if change <= k:
			ans = max(r - l + 1, ans)
	r += 1
r -= 1
while l <= n - 1:
	if txt[l] == 'a':
		countA -= 1
	else:
		countB -= 1
	change = min(countA, countB)
	if change <= k:
		ans = max(r - l + 1, ans)
	l += 1
print(ans)


(n, k) = map(int, input().split())
s = str(input())
(i, j, a, b, m) = (0, 0, 0, 0, 0)
while i < n:
	if s[i] == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) <= k:
		m = max(m, a + b)
	else:
		e = s[j]
		if e == 'a':
			a = a - 1
		else:
			b = b - 1
		m = max(m, a + b)
		j = j + 1
	i = i + 1
print(m)


(n, k) = map(int, input().split())
s = input()
m = k
a = s[:k].count('a')
b = k - a
l = 0
for r in range(k, len(s)):
	if s[r] == 'a':
		a += 1
	else:
		b += 1
	while min(a, b) > k:
		if s[l] == 'a':
			a -= 1
		else:
			b -= 1
		l += 1
	m = max(m, r - l + 1)
print(m)


__author__ = 'Utena'
(n, k) = map(int, input().split())
s = ['0'] + list(input())
beauty = 0
i = 0
j = 0
a = 0
b = 0
while i < n:
	i += 1
	if s[i] == 'a':
		a += 1
	if s[i] == 'b':
		b += 1
	while min(a, b) > k:
		j += 1
		if s[j] == 'a':
			a -= 1
		if s[j] == 'b':
			b -= 1
	if i - j > beauty:
		beauty = i - j
print(beauty)


import sys, math, collections
(n, k) = map(int, input().split())
s = input()
ans = 0
l1 = l2 = 0
temp = temp2 = 0
for r in range(n):
	temp += s[r] == 'a'
	temp2 += s[r] == 'b'
	while temp > k:
		temp -= s[l1] == 'a'
		l1 += 1
	while temp2 > k:
		temp2 -= s[l2] == 'b'
		l2 += 1
	ans = max(ans, r - l1 + 1, r - l2 + 1)
print(ans)


(n, k) = map(int, input().split())
lst = list(input())
(a, b, leng1, leng2) = ([0], [0], 0, 0)
for (i, x) in enumerate(lst):
	if x == 'a':
		a.append(i + 1)
		leng1 += 1
	else:
		b.append(i + 1)
		leng2 += 1
if k >= leng1 or k >= leng2:
	from sys import exit
	print(n)
	exit()
from bisect import bisect
res = -1
for (i, x) in enumerate(lst):
	i += 1
	if x == 'a':
		item = bisect(b, i)
		if item == 1:
			res = i
			continue
		elem = b[max(0, item - k - 1)] + 1
	else:
		item = bisect(a, i)
		if item == 1:
			res = i
			continue
		elem = a[max(0, item - k - 1)] + 1
	res = max(res, i - elem + 1)
print(res)


def solve(n, k, s):
	ans = 0
	c = {'a': 0, 'b': 0}
	l = 0
	cur_len = 0
	for r in range(n):
		cur_len += 1
		c[s[r]] += 1
		while l <= r and min(c.values()) > k:
			c[s[l]] -= 1
			cur_len -= 1
			l += 1
		ans = max(ans, cur_len)
	return ans
(n, k) = map(int, input().split())
s = input()
print(solve(n, k, s))


from itertools import accumulate
(n, k) = [int(x) for x in input().split()]
A = [1 if c == 'a' else 0 for c in input()]
P = [0] + list(accumulate(A))
(x, y) = (1, n + 1)
z = n // 2
while x != z:
	for i in range(n - z + 1):
		t = P[i + z] - P[i]
		if t >= z - k or t <= k:
			x = z
			break
	else:
		y = z
	z = (x + y) // 2
print(z)


def solve(n, k, l):
	ki = i = s = 0
	po = 1
	for j in range(n):
		s += l[j] == 0
		while s > k:
			s -= l[i] == 0
			i += 1
		if j - i > ki - po:
			(po, ki) = (i, j)
	return ki - po + 1
(n, k) = map(int, input().split())
s = input()
(a1, a2) = ([], [])
for i in range(n):
	if s[i] == 'a':
		a1.append(1)
		a2.append(0)
	else:
		a1.append(0)
		a2.append(1)
print(max(solve(n, k, a1), solve(n, k, a2)))


(n, k) = list(map(int, input().split()))
s = input()
l = 0
r = 0
ans = 0
num = 0
i = 0
while i < n:
	r += 1
	if s[i] == 'b':
		num += 1
		if num > k:
			ans = max(ans, i - l)
			while l < n and s[l] != 'b':
				l += 1
			l += 1
			num -= 1
	i += 1
ans = max(ans, i - l)
l = 0
r = 0
num = 0
i = 0
while i < n:
	r += 1
	if s[i] == 'a':
		num += 1
		if num > k:
			ans = max(ans, i - l)
			while l < n and s[l] != 'a':
				l += 1
			l += 1
			num -= 1
	i += 1
ans = max(ans, i - l)
print(ans)


from os import path
import sys, time, collections as c, math as m, pprint as p
(maxx, localsys, mod) = (float('inf'), 0, int(1000000000.0 + 7))
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
(n, k) = map(int, input().split())
s = input().rstrip('\n')
ans = a = b = j = 0
for i in range(n):
	(a, b) = (a + 1, b) if s[i] == 'a' else (a, b + 1)
	if min(a, b) > k:
		(a, b) = (a - 1, b) if s[j] == 'a' else (a, b - 1)
		j += 1
	else:
		ans += 1
print(ans)


(n, k) = map(int, input().split())
s = input()
freq = {'a': 0, 'b': 0}
for i in s:
	freq[i] = freq[i] + 1
char = 'b' if freq['a'] > freq['b'] else 'a'
if k >= freq[char]:
	print(n)
	exit()
cnts = []
cnt = 0
for i in s:
	if i != char:
		cnt += 1
	else:
		cnts.append(cnt)
		cnt = 0
if cnt != 0:
	cnts.append(cnt)
cnt_eq = []
cnt = 0
if freq['a'] == freq['b']:
	for i in s:
		if i == char:
			cnt += 1
		else:
			cnt_eq.append(cnt)
			cnt = 0
	if cnt != 0:
		cnt_eq.append(cnt)

def max_subarr(arr, k):
	init_sum = 0
	max_sum = 0
	if k == len(arr):
		return sum(arr)
	for i in range(len(arr)):
		if i < k:
			init_sum += arr[i]
			max_sum = init_sum
		else:
			init_sum += arr[i] - arr[i - k]
			max_sum = max(max_sum, init_sum)
	return max_sum
print(max(max_subarr(cnts, k + 1), max_subarr(cnt_eq, k + 1)) + k)


(n, k) = map(int, input().split())
s = list(input())
ans = 0
right = 0
cntb = 0
for left in range(n):
	while cntb <= k and right < n:
		if s[right] == 'b':
			cntb += 1
		if cntb == k + 1:
			cntb -= 1
			break
		right += 1
	ans = max(ans, right - left)
	if right == left:
		right += 1
	elif s[left] == 'b':
		cntb -= 1
right = 0
cnta = 0
for left in range(n):
	while cnta <= k and right < n:
		if s[right] == 'a':
			cnta += 1
		if cnta == k + 1:
			cnta -= 1
			break
		right += 1
	ans = max(ans, right - left)
	if right == left:
		right += 1
	elif s[left] == 'a':
		cnta -= 1
print(ans)


(n, k) = [int(s) for s in input().split(' ')]
str = input()

def length_of_longest_substring(str, k):
	(window_start, window_end, maxCharCount, maxLen) = (0, 0, 0, 0)
	char_freq = {}
	for window_end in range(len(str)):
		right_char = str[window_end]
		if right_char not in char_freq:
			char_freq[right_char] = 0
		char_freq[right_char] += 1
		maxCharCount = max(maxCharCount, char_freq[right_char])
		while window_end - window_start + 1 - maxCharCount > k:
			left_char = str[window_start]
			char_freq[left_char] -= 1
			window_start += 1
		maxLen = max(maxLen, window_end - window_start + 1)
	print(maxLen)
length_of_longest_substring(str, k)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def main():
	(n, k) = LI()
	s = S()
	r = 0
	c = collections.defaultdict(int)
	j = 0
	for i in range(n):
		c[s[i]] += 1
		while c['a'] > k and c['b'] > k:
			c[s[j]] -= 1
			j += 1
		t = i - j + 1
		if r < t:
			r = t
	return r
print(main())


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve(n, m):
	if n >= m:
		return n - m
	if m % 2:
		return 1 + solve(n, m + 1)
	return 1 + solve(n, m // 2)

def main():
	(n, k) = get_tuple()
	st = input()
	a = st[:k].count('a')
	b = k - a
	l = 0
	ans = k
	for r in range(k, n):
		if st[r] == 'a':
			a += 1
		else:
			b += 1
		while min(a, b) > k:
			if st[l] == 'a':
				a -= 1
			else:
				b -= 1
			l += 1
		ans = max(ans, r - l + 1)
	print(ans)
TestCases = False
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


(n, k) = map(int, input().split())
(counta, countb) = (0, 0)
s = input()
(l, r) = (0, 0)
maxlength = 0
while r < n:
	if s[r] == 'a':
		counta += 1
	else:
		countb += 1
	if counta <= k or countb <= k:
		maxlength = max(maxlength, r - l + 1)
	else:
		if s[l] == 'a':
			counta -= 1
		else:
			countb -= 1
		l += 1
	r += 1
print(maxlength)


aplha = [chr(i) for i in range(ord('a'), ord('z') + 1)]
(n, k) = map(int, input().split())
s = list(input())
out = 0
for i in aplha:
	l = 0
	r = 0
	t = k
	while l < n and r < n:
		if s[r] == i:
			r += 1
		elif t > 0:
			t -= 1
			r += 1
		elif s[l] == i:
			l += 1
		else:
			t += 1
			l += 1
		out = max(out, r - l)
print(out)


(n, k) = map(int, input().split())
s = input()
p1 = 0
c = 0
maxi = -1
for p0 in range(n):
	p1 = max(p1, p0)
	while p1 < n and (s[p1] == 'a' or c < k):
		if s[p1] == 'b':
			c += 1
		p1 += 1
	maxi = max(maxi, p1 - p0)
	if s[p0] == 'b':
		c -= 1
	c = max(c, 0)
p1 = 0
c = 0
for p0 in range(n):
	p1 = max(p1, p0)
	while p1 < n and (s[p1] == 'b' or c < k):
		if s[p1] == 'a':
			c += 1
		p1 += 1
	maxi = max(maxi, p1 - p0)
	if s[p0] == 'a':
		c -= 1
	c = max(c, 0)
print(maxi)


import math
from math import gcd, sqrt, floor, factorial, ceil
from bisect import bisect_left, bisect_right
import bisect
import sys
from sys import stdin, stdout
import os
sys.setrecursionlimit(pow(10, 7))
import collections
from collections import defaultdict, Counter
from statistics import median
from queue import Queue
inf = float('inf')
(n, k) = map(int, input().split())
s = input()
l = list(s)
a = 'a'
b = 'b'
m = []
for i in l:
	if i == a:
		m.append(b)
	else:
		m.append(a)
k1 = k
k2 = k
it1 = 0
it2 = 0

def fun(l):
	maxa = 0
	k1 = k
	k2 = k
	it1 = 0
	it2 = 0
	while 0 <= it1 < n and it2 < n:
		if l[it2] == b:
			pass
		elif k1 > 0:
			k1 -= 1
		else:
			while it1 < n and l[it1] == b:
				it1 += 1
			it1 += 1
		length = it2 - it1 + 1
		if maxa < length:
			maxa = length
		it2 += 1
	return maxa
maxa1 = fun(l)
maxa2 = fun(m)
ans = max(maxa1, maxa2)
print(ans)


(n, k) = map(int, input().split())
s = input()
a = 0
b = 0
left = 0
right = 0
for i in s:
	if i == 'a':
		a = a + 1
	else:
		b = b + 1
	if min(a, b) > k:
		if s[left] == 'a':
			a -= 1
		else:
			b -= 1
		left = left + 1
	else:
		right += 1
print(right)


(n, k) = input().split(' ')
n = int(n)
k = int(k)
str = input()

def analyze(str, char):
	ans = 0
	count_char = 0
	i = 0
	j = 0
	while True:
		if count_char <= k:
			ans = max(ans, j - i)
		if count_char > k:
			if str[i] == char:
				count_char -= 1
			i += 1
		if j >= n:
			break
		elif count_char <= k:
			j += 1
			if str[j - 1] == char:
				count_char += 1
	if count_char <= k:
		ans = max(ans, j - i)
	return ans
ans = max(analyze(str, 'a'), analyze(str, 'b'))
print(ans)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n, k) = I()
s = input()

def check(char):
	ans = 0
	count = 0
	i = j = 0
	while i < n:
		count += s[i] != char
		while j < i and count > k:
			count -= s[j] != char
			j += 1
		ans = max(ans, i - j + 1)
		i += 1
	return ans
print(max(check('a'), check('b')))


(n, k) = map(int, input().split())
S = input()
l = r = 0
a = b = 0
ans = 0
while r < n:
	if a <= k or a == 0 or b <= k or (b == 0):
		ans = max(ans, r - l)
		if S[r] == 'a':
			a += 1
		else:
			b += 1
		r += 1
	else:
		if S[l] == 'a':
			a -= 1
		else:
			b -= 1
		l += 1
	if a <= k or a == 0 or b <= k or (b == 0):
		ans = max(ans, r - l)
print(ans)


import collections
(n, k) = [int(x) for x in input().split(' ')]
s = input()
deq_a = collections.deque()
deq_b = collections.deque()
(l_a, l_b) = (10000000, 10000000)
(a, b) = (k, k)
(a_len, b_len) = (0, 0)
(max_a, max_b) = (0, 0)
for i in range(n):
	if s[i] == 'a':
		l_a = min(l_a, i)
		a_len += 1
	elif a > 0:
		deq_a.append(i)
		a -= 1
		a_len += 1
	elif len(deq_a) > 0:
		l_a = deq_a.popleft() + 1
		deq_a.append(i)
		a_len = i - l_a + 1
	else:
		a_len = 0
	max_a = max(a_len, max_a)
for i in range(n):
	if s[i] == 'b':
		l_b = min(l_b, i)
		b_len += 1
	elif b > 0:
		deq_b.append(i)
		b -= 1
		b_len += 1
	elif len(deq_b) > 0:
		l_b = deq_b.popleft() + 1
		deq_b.append(i)
		b_len = i - l_b + 1
	else:
		b_len = 0
	max_b = max(b_len, max_b)
print(max(max_a, max_b))


(n, l) = input().split()
n = int(n)
l = int(l)
string = input()
a = b = x = j = 0
for i in string:
	if i == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) > l:
		if string[j] == 'a':
			a -= 1
		else:
			b -= 1
		j += 1
	else:
		x += 1
print(x)


from sys import stdin, stdout

def fn(a, ch):
	ans = 0
	for i in range(n):
		(l, r) = (i, n - 1)
		while l <= r:
			mid = l + r >> 1
			req = a[i] + k - int(s[i] != ch)
			if a[mid] <= req:
				l = mid + 1
			else:
				r = mid - 1
		ans = max(ans, r - i + 1)
	return ans
for _ in range(1):
	(n, k) = list(map(int, stdin.readline().split()))
	s = input()
	make_a = []
	make_b = []
	make_a += [int(s[0] == 'a')]
	make_b += [int(s[0] == 'b')]
	for i in range(1, n):
		make_a += [make_a[-1] + int(s[i] == 'a')]
		make_b += [make_b[-1] + int(s[i] == 'b')]
	ans = max(fn(make_a, 'b'), fn(make_b, 'a'))
	print(ans)


(n, m) = map(int, input().split())
s = input()
(ans, a, b, c, l) = (0, 0, 0, 0, 0)
for i in s:
	if i == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) > m:
		if s[l] == 'a':
			a -= 1
		else:
			b -= 1
		l += 1
	else:
		ans += 1
print(ans)


(n, k) = [int(i) for i in input().split()]
s = input()

def beauty(x):
	ret = 0
	cnt = 0
	r = 0
	for l in range(n):
		while r < n and (cnt < k or s[r] != x):
			if s[r] == x:
				cnt += 1
			r += 1
		if s[l] == x:
			cnt -= 1
		ret = max(ret, r - l)
	return ret
print(max(beauty('a'), beauty('b')))
exit(0)


def getMax(s, i, j, t, k, n):
	res = 0
	count = 0
	while i < n:
		while j < n and count < k:
			if s[j] != t:
				count += 1
			j += 1
		while j < n and s[j] == t:
			j += 1
		res = max(res, j - i)
		while i < n and s[i] == t:
			i += 1
		if i < n:
			i += 1
			count -= 1
	return res
(n, k) = [int(x) for x in input().split()]
s = input()
print(max(getMax(s, 0, 0, 'a', k, n), getMax(s, 0, 0, 'b', k, n)))


import math
from decimal import *
import random
import sys
(n, k) = map(int, input().split())
s = str(input())
(L, r, no) = (0, 0, 0)
ans = 0
while r < n:
	if s[r] == 'a':
		no += 1
	if no > k:
		ans = max(ans, r - L)
		while no > k:
			if s[L] == 'a':
				no -= 1
			L += 1
		ans = max(ans, r + 1 - L)
	else:
		ans = max(ans, r + 1 - L)
	r += 1
(L, r, no) = (0, 0, 0)
while r < n:
	if s[r] == 'b':
		no += 1
	if no > k:
		ans = max(ans, r - L)
		while no > k:
			if s[L] == 'b':
				no -= 1
			L += 1
		ans = max(ans, r + 1 - L)
	else:
		ans = max(ans, r + 1 - L)
	r += 1
print(ans)


def bigsub(s, n, k, x):
	j = 0
	i = 0
	tmp = 0
	ans = 0
	ck = 0
	while j < n and i < n:
		if s[j] != x:
			tmp += 1
			j += 1
			if tmp > ans:
				ans = tmp
		else:
			ck += 1
			if ck <= k:
				j += 1
				tmp += 1
				if tmp > ans:
					ans = tmp
			else:
				while ck > k and i < n:
					if s[i] == x:
						ck -= 1
					i += 1
					tmp -= 1
				ck -= 1
	return ans
(n, k) = map(int, input().split())
s = input()
sol = max(bigsub(s, n, k, 'b'), bigsub(s, n, k, 'a'))
print(sol)


read = lambda : list(map(int, input().split()))
(n, k) = read()
s = input()
i = j = 0
cur = k
while cur and j < n:
	if s[j] == 'a':
		cur -= 1
	j += 1
while j < n and s[j] == 'b':
	j += 1
ans = j
while j < n:
	while i < n and s[i] == 'b':
		i += 1
	i += 1
	j += 1
	while j < n and s[j] == 'b':
		j += 1
	ans = max(ans, j - i)
i = j = 0
cur = k
while cur and j < n:
	if s[j] == 'b':
		cur -= 1
	j += 1
while j < n and s[j] == 'a':
	j += 1
ans = max(ans, j)
while j < n:
	while i < n and s[i] == 'a':
		i += 1
	i += 1
	j += 1
	while j < n and s[j] == 'a':
		j += 1
	ans = max(ans, j - i)
print(ans)


from sys import stdin
input = stdin.readline
from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
from math import factorial as f, ceil, gcd, sqrt, log
mp = lambda : map(int, input().split())
it = lambda : int(input())
ls = lambda : list(input().strip())
mt = lambda r: [list(mp()) for _ in range(r)]
lcm = lambda a, b: a * b // gcd(a, b)

def fibo_n(n):
	return ((1 + sqrt(5)) / 2) ** n / sqrt(5)
mod = 1000000007
(a, b) = mp()
s = input().strip()
st = 1
en = a

def solve(s, n, k):
	d = dd(lambda : 0)
	mx = 0
	for i in range(n):
		d[s[i]] += 1
		mx = max(mx, d[s[i]])
	if k >= n - mx:
		return 1
	for j in range(n, a):
		d[s[j]] += 1
		d[s[j - n]] -= 1
		mx = max(list(d.values()))
		if k >= n - mx:
			return 1
	return 0
while st <= en:
	mid = (st + en) // 2
	if solve(s, mid, b):
		ans = mid
		st = mid + 1
	else:
		en = mid - 1
print(ans)


(n, k) = map(int, input().split())
a = input()
ka = 0
kb = 0
c = 0
answer = 0
for i in range(n):
	if a[i] == 'a':
		ka += 1
	else:
		kb += 1
	s = min(ka, kb)
	if k < s:
		if a[c] == 'a':
			ka -= 1
		else:
			kb -= 1
		c += 1
	else:
		answer += 1
print(answer)


(n, k) = map(int, input().split())
st = 0
end = 1
s = input()
l = [0] * (n + 1)
for i in range(len(s)):
	l[i + 1] = 1 if s[i] == 'a' else 0
su = 0
m = 0
while end < n + 1:
	su += l[end]
	if su > k and end - st - su > k:
		st += 1
		su -= l[st]
		m = max(m, st - end)
	end += 1
m = max(m, end - st - 1)
print(m)


from math import ceil

def mlt():
	return map(int, input().split())
(x, y) = mlt()
s = list(input())

def f(s, c):
	a = 0
	b = 0
	l = 0
	r = 0
	mx = 0
	while l <= r and r < x:
		if s[r] == c:
			a += 1
		else:
			b += 1
			if b > y:
				while l <= r:
					if s[l] == c:
						a -= 1
						l += 1
					else:
						b -= 1
						l += 1
						if b == y:
							break
		mx = max(mx, r - l + 1)
		r += 1
	return mx
print(max(f(s, 'b'), f(s, 'a')))


(n, limit) = input().split()
limit = int(limit)
string = input()
start = 0
n_a = 0
n_b = 0
for letter in string:
	if letter == 'a':
		n_a += 1
	else:
		n_b += 1
	if n_a > limit and n_b > limit:
		if string[start] == 'a':
			n_a -= 1
		else:
			n_b -= 1
		start += 1
print(n_a + n_b)


def check(s, x, k):
	a = s[:x].count('a')
	b = s[:x].count('b')
	i = x
	while i < len(s):
		if min(a, b) <= k:
			return True
		if s[i - x] == 'a':
			a -= 1
		else:
			b -= 1
		if s[i] == 'a':
			a += 1
		else:
			b += 1
		i += 1
	if min(a, b) <= k:
		return True
	return False
(n, k) = map(int, input().split())
s = input()
left = 1
right = n
ans = 1
while left <= right:
	mid = (left + right) // 2
	if check(s, mid, k):
		ans = mid
		left = mid + 1
	else:
		right = mid - 1
print(ans)


import math
(n, k) = map(int, input().split())
s = str(input())
d = {'a': 0, 'b': 0}
max_len = 1
r = 0
l = 0
while r < n:
	d[s[r]] += 1
	r += 1
	if min(d['a'], d['b']) > k:
		for i in range(l, r):
			d[s[i]] -= 1
			if min(d['a'], d['b']) <= k:
				l = i + 1
				break
	max_len = max(max_len, d['a'] + d['b'])
print(max_len)


def vasia(n, k, w):
	pos = 0
	suma = 0
	sumb = 0
	con = 0
	for i in range(n):
		if w[i] == 'a':
			suma = suma + 1
		elif w[i] == 'b':
			sumb = sumb + 1
		if min(suma, sumb) <= k:
			con = max(con, suma + sumb)
		else:
			res = w[pos]
			if res == 'a':
				suma = suma - 1
			elif res == 'b':
				sumb = sumb - 1
			con = max(con, suma + sumb)
			pos = pos + 1
	return con

def main():
	(n, k) = map(int, input().split())
	w = list(input())
	print(vasia(n, k, w))
main()


def solve(i, j):
	alpha = {'a': 0, 'b': 0}
	alpha[string[i]] += 1
	alpha[string[j]] += 1
	m = 0
	while i < j < len(string):
		a = alpha['a']
		b = alpha['b']
		if a <= k or b <= k:
			m = max(m, j - i + 1)
		if a > k and b > k:
			alpha[string[i]] -= 1
			i += 1
		else:
			j += 1
			if j < len(string):
				alpha[string[j]] += 1
	return (i, j, m)
(n, k) = map(int, input().split())
string = input()
if 'a' not in string or 'b' not in string:
	print(n)
else:
	i = 0
	j = 1
	m = 0
	while i < j < len(string):
		(i, j, m2) = solve(i, j)
		m = max(m, m2)
		if i == j:
			j += 1
	print(m)


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math

def possible(freq, l, k):
	for i in range(l, len(freq)):
		val = freq[i] - freq[i - l]
		alt = l - val
		if val + k >= l or alt + k >= l:
			return True
	return False

def solve():
	maxim = 0
	(n, k) = map(int, input().split())
	s = list(input())
	if s[-1] == '\n':
		s.pop()
	freq = [0]
	for x in s:
		if x == 'a':
			if len(freq) == 0:
				freq.append(1)
			else:
				freq.append(freq[-1] + 1)
		else:
			freq.append(freq[-1])
	(low, high) = (0, n + 1)
	while low < high:
		mid = (high - low) // 2 + low
		if possible(freq, mid, k):
			maxim = max(maxim, mid)
			low = mid + 1
		else:
			high = mid
	print(maxim)
for _ in range(1):
	solve()


(n, k) = input().split(' ')
n = int(n)
k = int(k)
s = input()

def stack(s, more, less, k):
	flag = True
	count = k
	pos = []
	maxsize = -1
	decrement = 0
	for (index, ch) in enumerate(s):
		if ch == less:
			if count > 0:
				count -= 1
				pos.append(index)
				flag = True
			else:
				pos.append(index)
				if flag:
					decrement = 0
					flag = False
					size = index - decrement
				else:
					decrement = pos.pop(0)
					size = index - decrement - 1
				if size > maxsize:
					maxsize = size
		if index == len(s) - 1 and flag == False:
			size = index - pos.pop(0)
			if size > maxsize:
				maxsize = size
		elif index == len(s) - 1 and flag == True:
			maxsize = index + 1
	return maxsize
ans1 = stack(s, 'a', 'b', k)
ans2 = stack(s, 'b', 'a', k)
if ans1 > ans2:
	print(ans1)
else:
	print(ans2)


def solve(s, k, target):
	n = len(s)
	acum = [0] * n
	first = dict()
	for (i, v) in enumerate(s):
		if i > 0:
			acum[i] = acum[i - 1]
		if v != target:
			acum[i] += 1
		if acum[i] not in first:
			first[acum[i]] = i
	best = 0
	for i in range(n):
		curr = acum[i - 1] if i > 0 else 0
		hi = curr + k + 1
		pos = first.get(hi, n) - 1
		res = pos - i + 1
		best = max(best, res)
	return best
(n, k) = map(int, input().split())
s = input()
print(max(solve(s, k, 'a'), solve(s, k, 'b')))


(n, k) = map(int, input().split())
s = input()
(res, cnta, cntb, oldi) = (0, 0, 0, 0)
for i in range(n):
	if s[i] == 'a':
		cnta += 1
	else:
		cntb += 1
	while oldi <= i and k < min(cnta, cntb):
		if s[oldi] == 'a':
			cnta -= 1
		else:
			cntb -= 1
		oldi += 1
	res = max(res, i - oldi + 1)
print(res)


(n, k) = map(int, input().split())
pref = [0]
arr = [0 for i in range(n)]
s = input()
for i in range(n):
	arr[i] = ord(s[i]) - ord('a')
	pref.append(pref[-1] + arr[i])

def sat(low, ind):
	global k
	return pref[ind + 1] - pref[low] <= k or pref[ind + 1] - pref[low] >= ind - low + 1 - k

def bs(lo, hi):
	ret = -1
	low = lo
	while lo <= hi:
		mid = (lo + hi) // 2
		if sat(low, mid):
			ret = max(ret, mid)
			lo = mid + 1
		else:
			hi = mid - 1
	return ret
ans = 0
for i in range(n):
	ans = max(ans, bs(i, n - 1) - i + 1)
print(ans)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, k) = value()
a = list(input())
KthA = -1
index = defaultdict(list)
for i in range(n):
	index[a[i]].append(i)
size = len(index['b'])
a = 'b'
if size <= k:
	maxA = (0, n - 1)
else:
	start = 0
	end = index[a][k] - 1
	maxA = (start, end)
	i = k
	while i < len(index[a]):
		start = index[a][i - k] + 1
		try:
			end = index[a][i + 1] - 1
		except:
			end = n - 1
		if end - start > maxA[1] - maxA[0]:
			maxA = (start, end)
		i += 1
ans1 = maxA[1] - maxA[0] + 1
size = len(index['a'])
a = 'a'
if size <= k:
	maxA = (0, n - 1)
else:
	start = 0
	end = index[a][k] - 1
	maxA = (start, end)
	i = k
	while i < len(index[a]):
		start = index[a][i - k] + 1
		try:
			end = index[a][i + 1] - 1
		except:
			end = n - 1
		if end - start > maxA[1] - maxA[0]:
			maxA = (start, end)
		i += 1
ans2 = maxA[1] - maxA[0] + 1
print(max(ans1, ans2))


(n, k) = map(int, input().split(' '))
s = input()
res = 0
i = 0
j = 0
h = 0
for l in s:
	i += 1
	if l != 'a':
		if h < k:
			h += 1
		else:
			for u in range(j, i):
				if s[u] == 'b':
					j = u + 1
					break
			else:
				j = i
	res = max(res, i - j)
i = 0
j = 0
h = 0
for l in s:
	i += 1
	if l != 'b':
		if h < k:
			h += 1
		else:
			for u in range(j, i):
				if s[u] == 'a':
					j = u + 1
					break
			else:
				j = i
	res = max(res, i - j)
print(res)


(n, k) = list(map(int, input().split()))
s = input()
sums = [0] * (n + 1)
for i in range(n):
	if s[i] == 'a':
		sums[i] = sums[i - 1] + 1
	else:
		sums[i] = sums[i - 1]
l = 0
r = 0

def check_interval(l, r):
	length = r - l + 1
	a_count = sums[r] - sums[l - 1]
	return a_count <= k or length - a_count <= k
maxl = 1
while l < n:
	r = l + maxl
	while r < n and check_interval(l, r):
		r += 1
		maxl += 1
	l += 1
print(maxl)


import sys
f = sys.stdin
(n, k) = map(int, f.readline().strip().split())
s = f.readline()
i = 0
j = 0
curmx = k
a = 0
b = 0
count = [0] * 26
while i < len(s):
	while j < len(s) and min(a, b) <= k:
		if s[j] == 'a':
			a += 1
		else:
			b += 1
		j += 1
	curmx = max(curmx, a + b - 1)
	if j == len(s):
		break
	if s[i] == 'a':
		a -= 1
	else:
		b -= 1
	i += 1
print(curmx)


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def exact(num):
	if abs(num - round(num)) <= 10 ** (-9):
		return round(num)
	return num

def findMaxx(lst, char, n, k):
	want = ''
	if char == 'a':
		want = 'b'
	else:
		want = 'a'
	i = 0
	j = 0
	countWant = 0
	prev = 1
	ans = 0
	while i < n and j < n:
		if prev == 1 and lst[j] == want:
			countWant += 1
		if prev == 0 and lst[i - 1] == want:
			countWant -= 1
		if countWant > k:
			prev = 0
			i += 1
		else:
			prev = 1
			j += 1
		ans = max(ans, j - i)
	return ans

def solve(n, k, lst):
	a = findMaxx(lst, 'a', n, k)
	b = findMaxx(lst, 'b', n, k)
	return max(a, b)
(n, k) = list(map(int, input().split()))
lst = input()
print(solve(n, k, lst))


s = input()
s1 = s.split()
K = int(s1[1])
s = input()
i = 0
j = 0
k = K
maxlen = 0
while j < len(s):
	if s[j] == 'a':
		j = j + 1
	elif k > 0:
		k = k - 1
		j = j + 1
	else:
		maxlen = max(maxlen, j - i)
		while k == 0:
			if s[i] == 'b':
				k = k + 1
			i = i + 1
maxlen = max(maxlen, len(s) - i)
i = 0
j = 0
k = K
while j < len(s):
	if s[j] == 'b':
		j = j + 1
	elif k > 0:
		k = k - 1
		j = j + 1
	else:
		maxlen = max(maxlen, j - i)
		while k == 0:
			if s[i] == 'a':
				k = k + 1
			i = i + 1
maxlen = max(maxlen, len(s) - i)
print(maxlen)


(n, k) = map(int, input().split())
s = input()
(i, j) = (0, 0)
ans = 0
dp = [0, 0]
while i < n:
	dp[ord(s[i]) - ord('a')] += 1
	if min(dp[0], dp[1]) > k:
		while min(dp[0], dp[1]) > k and j <= i:
			dp[ord(s[j]) - ord('a')] -= 1
			j += 1
	else:
		ans = max(ans, dp[0] + dp[1])
	i += 1
print(ans)


l = input().split()
n = int(l[0])
k = int(l[1])
s = input()
maxa = []
i = 0
j = 0
numofs = 0
while i < n:
	while j < n and numofs <= k:
		if s[j] == 'a':
			j += 1
		elif numofs < k:
			numofs += 1
			j += 1
		else:
			break
	maxa.append(j - i + 1)
	if s[i] == 'b':
		numofs -= 1
		i += 1
	else:
		i += 1
i = 0
j = 0
numofs = 0
while i < n:
	while j < n and numofs <= k:
		if s[j] == 'b':
			j += 1
		elif numofs < k:
			numofs += 1
			j += 1
		else:
			break
	maxa.append(j - i + 1)
	if s[i] == 'a':
		numofs -= 1
		i += 1
	else:
		i += 1
print(max(maxa) - 1)


MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, k) = f()
s = si()
(k1, k2) = (k, k)
mx = 0
(i, j) = (0, 0)
while j < n:
	while j < n:
		if s[j] == 'b':
			if k1 > 0:
				k1 -= 1
			else:
				break
		j += 1
	mx = max(mx, j - i)
	while i < j:
		if s[i] == 'b':
			break
		i += 1
	i += 1
	k1 += 1
(i, j) = (0, 0)
while j < n:
	while j < n:
		if s[j] == 'a':
			if k2 > 0:
				k2 -= 1
			else:
				break
		j += 1
	mx = max(mx, j - i)
	while i < j:
		if s[i] == 'a':
			break
		i += 1
	i += 1
	k2 += 1
print(mx)


def try_for_letter(w, letter):
	l = 0
	r = 0
	curr_k = 0
	best = 0
	while r < n:
		if w[r] != letter:
			curr_k += 1
		if curr_k <= k:
			best = max(best, r - l + 1)
		else:
			while curr_k > k:
				if w[l] != letter:
					curr_k -= 1
				l += 1
		r += 1
	return best
(n, k) = map(int, input().split())
w = input()
print(max(try_for_letter(w, 'a'), try_for_letter(w, 'b')))


(n, k) = map(int, input().split())
mp = input()
c = {'a': 0, 'b': 0}
aa = 0
l = 0
for m in mp:
	c[m] += 1
	if min(c['a'], c['b']) > k:
		c[mp[l]] -= 1
		l += 1
	else:
		aa += 1
print(aa)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
(n, k) = zz()
s = z()
m = k
a = s[:k].count('a')
b = k - a
l = 0
for i in range(k, n):
	if s[i] == 'a':
		a += 1
	else:
		b += 1
	while min(a, b) > k:
		if s[l] == 'a':
			a -= 1
		else:
			b -= 1
		l += 1
	m = max(m, i - l + 1)
print(m)


(n, k) = map(int, input().split())
lis = [[0, 0] for i in range(n + 1)]
s = list(input())
ans = 0
for i in range(1, n + 1):
	if s[i - 1] == 'a':
		lis[i][0] = lis[i - 1][0] + 1
		lis[i][1] = lis[i - 1][1]
	else:
		lis[i][1] = lis[i - 1][1] + 1
		lis[i][0] = lis[i - 1][0]
for i in range(1, n + 1):
	l = i
	r = n
	while l <= r:
		mid = l + (r - l) // 2
		ca = lis[mid][0] - lis[i - 1][0]
		cb = lis[mid][1] - lis[i - 1][1]
		chan = min(ca, cb)
		if chan > k:
			r = mid - 1
		else:
			l = mid + 1
	ans = max(ans, r - i + 1)
print(ans)


import os
import sys
from io import BytesIO, IOBase

def pos(mid, pre, n, k):
	for x in range(mid, n + 1):
		if min(pre[x][0] - pre[x - mid][0], pre[x][1] - pre[x - mid][1]) <= k:
			return True
	return False

def main():
	(n, k) = map(int, input().split(' '))
	s = input()
	low = 1
	high = n
	mid = 0
	pre = [[0, 0]]
	(ca, cb) = (0, 0)
	for x in s:
		if x == 'a':
			ca += 1
		else:
			cb += 1
		pre.append([ca, cb])
	while low <= high:
		mid = (low + high) // 2
		if pos(mid, pre, n, k) == True and pos(mid + 1, pre, n, k) == False:
			break
		elif pos(mid, pre, n, k):
			low = mid + 1
		else:
			high = mid - 1
	print(mid)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys

def solve(ch):
	l = 0
	ans = 0
	maxx = 0
	for r in range(n):
		if ch == 'a':
			if s[r] == 'b':
				maxx += 1
		elif s[r] == 'a':
			maxx += 1
		while maxx > k:
			if ch == 'a':
				if s[l] == 'b':
					maxx -= 1
			elif s[l] == 'a':
				maxx -= 1
			l += 1
		ans = max(ans, r - l + 1)
	return ans
(n, k) = map(int, sys.stdin.readline().split())
s = input()
a1 = solve('a')
a2 = solve('b')
print(max(a1, a2))


from sys import stdin
input = iter(stdin.readlines()).__next__
(n, k) = map(int, input().split())
string = input().strip()
(p1a, p1b, p2) = (0, 0, 0)
max_length = 0
(changed_a, changed_b) = (0, 0)
while p2 < n:
	if string[p2] == 'b':
		changed_a += 1
	else:
		changed_b += 1
	if changed_a > k:
		while True:
			p1a += 1
			if string[p1a - 1] == 'b':
				break
		changed_a -= 1
	if changed_b > k:
		while True:
			p1b += 1
			if string[p1b - 1] == 'a':
				break
		changed_b -= 1
	p2 += 1
	max_length = max(max_length, p2 - p1a, p2 - p1b)
print(max_length)


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def solve(c, s, k):
	global ans
	r = 0
	balance = 0
	for i in range(len(s)):
		while r < len(s) and (s[r] == c or balance < k):
			if s[r] != c:
				balance += 1
			r += 1
		ans = max(ans, r - i)
		if s[i] != c:
			balance -= 1
	return

def main():
	(n, k) = get_ints()
	s = input().strip()
	solve('a', s, k)
	solve('b', s, k)
	print(ans)
global ans
ans = 0
main()


(n, k) = map(int, input().split())
s = input()
a = 0
b = 0
ff = -1
pp = 0
for i in range(n):
	if s[i] == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) <= k:
		ff = max(a + b, ff)
	else:
		if s[pp] == 'a':
			a -= 1
		else:
			b -= 1
		pp += 1
if min(a, b) <= k:
	ff = max(a + b, ff)
print(ff)


def calc(string, k, char):
	offsets = [i for (i, v) in enumerate(string) if v != char]
	if k >= len(offsets):
		return len(string)
	left_idx = 0
	result = max(offsets[k], len(string) - offsets[len(offsets) - k - 1] - 1)
	for end_idx in range(k, len(offsets) - 1):
		right = offsets[end_idx + 1] - 1
		left = offsets[left_idx] + 1
		result = max(result, right - left + 1)
		left_idx += 1
	return result

def main():
	(n, k) = map(int, input().split())
	string = input()
	print(max(calc(string, k, 'a'), calc(string, k, 'b')))
main()


def count():
	global ca, cb
	if s[r] == 'a':
		ca += 1
	else:
		cb += 1
(n, k) = map(int, input().split())
s = input()
l = 0
r = 0
sm = 0
mx = 0
ca = 0
cb = 0
count()
while l < n:
	while min(ca, cb) <= k:
		sm += 1
		r += 1
		if r == n:
			break
		count()
	if sm > mx:
		mx = sm
	if r == n:
		break
	if s[l] == 'a':
		ca -= 1
	else:
		cb -= 1
	sm -= 1
	l += 1
print(mx)


(n, k) = map(int, input().split())
a = [char for char in input()]
pointer_esquerda = 0
pointer_direita = 0
mov = k
len_maior = 0
len_atual = 0
while pointer_esquerda <= n - 1:
	while mov >= 0 and pointer_direita <= n - 1:
		if a[pointer_direita] == 'b' and mov - 1 >= 0:
			mov -= 1
			pointer_direita += 1
			len_atual += 1
			if len_atual > len_maior:
				len_maior = len_atual
		elif a[pointer_direita] == 'a':
			pointer_direita += 1
			len_atual += 1
			if len_atual > len_maior:
				len_maior = len_atual
		elif mov - 1 < 0:
			break
	if a[pointer_esquerda] == 'b':
		mov += 1
	len_atual -= 1
	if len_atual > len_maior:
		len_maior = len_atual
	pointer_esquerda += 1
len_atual = 0
pointer_esquerda = 0
pointer_direita = 0
mov = k
while pointer_esquerda <= n - 1:
	while mov >= 0 and pointer_direita <= n - 1:
		if a[pointer_direita] == 'a' and mov - 1 >= 0:
			mov -= 1
			pointer_direita += 1
			len_atual += 1
			if len_atual > len_maior:
				len_maior = len_atual
		elif a[pointer_direita] == 'b':
			pointer_direita += 1
			len_atual += 1
			if len_atual > len_maior:
				len_maior = len_atual
		elif mov - 1 < 0:
			break
	if a[pointer_esquerda] == 'a':
		mov += 1
	len_atual -= 1
	if len_atual > len_maior:
		len_maior = len_atual
	pointer_esquerda += 1
print(len_maior)


import sys, math, heapq, copy
from collections import defaultdict, deque
from bisect import bisect_left, bisect_right
from functools import cmp_to_key
from itertools import permutations, combinations, combinations_with_replacement
mod = 1000000007

def get_int():
	return int(sys.stdin.readline().strip())

def get_str():
	return sys.stdin.readline().strip()

def get_float():
	return float(sys.stdin.readline().strip())

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_strs():
	return map(str, sys.stdin.readline().strip().split())

def get_floats():
	return map(float, sys.stdin.readline().strip().split())

def list_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def list_strs():
	return list(map(str, sys.stdin.readline().strip().split()))

def list_floats():
	return list(map(float, sys.stdin.readline().strip().split()))

def fun(s, n, k, key):
	start = end = 0
	res = 0
	while end < n:
		if s[end] != key and k > 0:
			k -= 1
		elif s[end] != key:
			res = max(res, end - start)
			while start < end and k == 0:
				if s[start] != key:
					k += 1
				start += 1
			if start == end and k == 0:
				start += 1
			else:
				k -= 1
		end += 1
	res = max(res, end - start)
	return res
(n, k) = get_ints()
s = get_str()
a = fun(s, n, k, 'a')
b = fun(s, n, k, 'b')
print(max(a, b))


[n, k] = [int(x) for x in input().split()]
abstring = input()
nb_a = 0
nb_b = 0
s = 0
count_start = 0
for i in range(n):
	if abstring[i] == 'a':
		nb_a += 1
	else:
		nb_b += 1
	if nb_b <= k or nb_a <= k:
		s += 1
	else:
		if abstring[count_start] == 'a':
			nb_a -= 1
		else:
			nb_b -= 1
		count_start += 1
print(s)


def f():
	(n, k) = map(int, input().split())
	s = input()
	cnta = [0]
	cntb = [0]
	for c in s:
		cnta.append(cnta[-1] + (c == 'a'))
		cntb.append(cntb[-1] + (c == 'b'))
	l = 1
	r = len(s)
	while l < r:
		m = (l + r + 1) // 2
		flag = False
		for n in range(len(s) - m + 1):
			if cntb[n + m] - cntb[n] <= k or cnta[n + m] - cnta[n] <= k:
				flag = True
		if flag:
			l = m
		else:
			r = m - 1
	print(l)
f()


def answer(n, k, A):
	if n == 1:
		return 1
	dp = [0] * (n + 1)
	for i in range(1, n + 1):
		if A[i - 1] == 'a':
			dp[i] = dp[i - 1] + 1
		else:
			dp[i] = dp[i - 1]
	l = 0
	r = 0
	maxi = 0
	while r >= l and r < n:
		x = dp[r + 1] - dp[l]
		if min(x, r + 1 - l - x) <= k:
			r += 1
		else:
			maxi = max(maxi, r - l)
			l += 1
	maxi = max(maxi, r - l)
	return maxi
(n, k) = map(int, input().split())
A = input()
print(answer(n, k, A))


def testa_se_da(valor, a, k, a_b):
	var = a_b

	def consegue(soma):
		if soma <= k:
			return True
		else:
			return False
	pos_esquerda = 0
	n = len(a)
	pos_direita = pos_esquerda + valor
	soma = 0
	for i in range(pos_esquerda, pos_direita):
		if a[i] != var:
			soma += 1
	if consegue(soma):
		return True
	while pos_direita <= n - 1:
		if a[pos_direita] != var:
			soma += 1
		if a[pos_esquerda] != var:
			soma -= 1
		if consegue(soma):
			return True
		pos_esquerda += 1
		pos_direita += 1
	return False
(n, k) = map(int, input().split())
a = [char for char in input()]
esquerda = 0
direita = n
melhor = 0
while esquerda <= direita:
	meio = (esquerda + direita) // 2
	da_a = testa_se_da(meio, a, k, 'a')
	da_b = testa_se_da(meio, a, k, 'b')
	if da_a or da_b:
		if meio > melhor:
			melhor = meio
		esquerda = meio + 1
	else:
		direita = meio - 1
print(melhor)


(n, k) = map(int, input().split())
s = input()
maxi = 0
a = 0
b = 0
st = 0
for i in range(0, n):
	if s[i] == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) > k:
		if s[st] == 'a':
			a -= 1
		else:
			b -= 1
		st += 1
	else:
		maxi += 1
print(maxi)


import os
from math import *
(n, k) = map(int, input().split())
arr = input()
arr = list(arr)
a = list(filter(lambda x: x == 'a', arr))
b = list(filter(lambda x: x == 'b', arr))
x = ''
if len(a) >= len(b):
	x = 'b'
else:
	x = 'a'
if k == 0:
	ans = 0
	count = 1
	for i in range(n - 1):
		if arr[i] == arr[i + 1]:
			count += 1
		else:
			if ans < count:
				ans = count
			count = 1
	if ans < count:
		ans = count
	print(ans)
else:
	fp = 0
	ans = 0
	count = 0
	brr = [0]
	checkpos = 0
	for i in range(n):
		if arr[i] == x:
			count += 1
			brr.append(i)
		if count > k:
			count -= 1
			if checkpos == 0:
				ans = i - brr[checkpos]
			elif ans < i - brr[checkpos] - 1:
				ans = i - brr[checkpos] - 1
			checkpos += 1
			fp = i
	if len(brr) - 1 <= k:
		print(n)
	else:
		if ans < n - brr[-1 - k] - 1:
			ans = n - 1 - brr[checkpos]
		print(ans)


(n, k) = map(int, input().split())
s = input()
(l, r) = (0, -1)
cnt = 0
ans = 0
while l != n:
	while r + 1 != n and min(cnt + int(s[r + 1] == 'a'), r - l + 2 - (cnt + int(s[r + 1] == 'a'))) <= k:
		r += 1
		cnt += int(s[r] == 'a')
	ans = max(ans, r - l + 1)
	cnt -= int(s[l] == 'a')
	l += 1
print(ans)


import bisect
import sys

def read_line():
	return sys.stdin.readline().strip()
(n, k) = [int(x) for x in read_line().split()]
s = read_line()
pref_a = [0] * n
pref_b = [0] * n
if s[0] == 'a':
	pref_a[0] = 1
else:
	pref_b[0] = 1
for ix in range(1, n):
	ch = s[ix]
	pref_a[ix] = pref_a[ix - 1] + (1 if ch == 'a' else 0)
	pref_b[ix] = pref_b[ix - 1] + (1 if ch == 'b' else 0)
ans = 1
for ix_st in range(n):
	end_change_as = bisect.bisect(pref_a, pref_a[ix_st] + k - (1 if s[ix_st] == 'a' else 0))
	end_change_bs = bisect.bisect(pref_b, pref_b[ix_st] + k - (1 if s[ix_st] == 'b' else 0))
	ans = max(ans, max(end_change_as, end_change_bs) - ix_st)
print(ans)


def occurence_list(string):
	o = [[0 for i in range(2)] for j in range(len(string))]
	for (i, j) in enumerate(string):
		o[i][ord(j) - ord('a')] += 1
	for i in range(1, len(string)):
		for j in range(0, 2):
			o[i][j] += o[i - 1][j]
	return o

def freq(o, l, r, target):
	if l == 0:
		return o[r][ord(target) - ord('a')]
	else:
		return o[r][ord(target) - ord('a')] - o[l - 1][ord(target) - ord('a')]
(n, k) = list(map(int, input().split()))
s = input()
if n == 1:
	print(1)
else:
	l = 0
	r = 0
	o = occurence_list(s)
	maxm_l = 1
	curr_l = 1
	while l <= r:
		if r == n - 1:
			break
		if min(r + 2 - l - freq(o, l, r + 1, 'a'), r + 2 - l - freq(o, l, r + 1, 'b')) <= k:
			r += 1
			curr_l += 1
			maxm_l = max(curr_l, maxm_l)
		else:
			if l == r:
				r += 1
			l += 1
			curr_l = r + 1 - l
			maxm_l = max(curr_l, maxm_l)
	print(maxm_l)


(n, k) = map(int, input().split())
s = input()
mx = 0
(i, j, cn) = (0, 0, 0)
while j < n:
	if s[j] == 'b':
		cn += 1
	while cn > k:
		if s[i] == 'b':
			cn -= 1
		i += 1
	mx = max(j - i + 1, mx)
	j += 1
(i, j, cn) = (0, 0, 0)
while j < n:
	if s[j] == 'a':
		cn += 1
	while cn > k:
		if s[i] == 'a':
			cn -= 1
		i += 1
	mx = max(j - i + 1, mx)
	j += 1
print(mx)


def find(s, n, k, constant):
	pref = [0]
	for x in s:
		if x == constant:
			pref.append(pref[-1] + 1)
		else:
			pref.append(pref[-1])
	(i, j) = (1, 1)
	ans = 0
	while i <= n and j <= n:
		nbs = pref[j] - pref[i - 1]
		if nbs <= k:
			ans = max(ans, j - i + 1)
			j += 1
		else:
			i += 1
	return ans
(n, k) = map(int, input().split())
s = input()
if k == 0:
	ans = 0
	cnt = 1
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			cnt += 1
		else:
			ans = max(ans, cnt)
			cnt = 1
	ans = max(ans, cnt)
	print(ans)
else:
	ans = find(s, n, k, 'b')
	ans = max(ans, find(s, n, k, 'a'))
	print(ans)


(n, k) = map(int, input().split())
a = list(input())
ca = k
i = 0
j = 0
aa = 0
ab = 0
ma = 0
mb = 0
while j < n:
	if a[j] == 'a':
		j = j + 1
		aa = aa + 1
	elif a[j] == 'b' and ca > 0:
		j = j + 1
		aa = aa + 1
		ca = ca - 1
	else:
		if a[i] == 'b':
			ca = ca + 1
		i = i + 1
		aa = aa - 1
	if ma < aa:
		ma = aa
ca = k
i = 0
j = 0
while j < n:
	if a[j] == 'b':
		j = j + 1
		ab = ab + 1
	elif a[j] == 'a' and ca > 0:
		j = j + 1
		ab = ab + 1
		ca = ca - 1
	else:
		if a[i] == 'a':
			ca = ca + 1
		i = i + 1
		ab = ab - 1
	if mb < ab:
		mb = ab
print(max(ma, mb))


(n, k) = map(int, input().split())
w = input()
(ans, i, j) = (0, 0, -1)
perm = k
(a, b) = (0, 0)
if k >= w.count('a') or k >= w.count('b'):
	ans = n
else:
	while i < n:
		if i > 0:
			if w[i - 1] == 'a':
				a -= 1
			else:
				b -= 1
			if w[i] == 'a' and w[i] != w[i - 1]:
				perm = k - b
			elif w[i] == 'b' and w[i] != w[i - 1]:
				perm = k - a
		while j + 1 < n:
			if w[j + 1] == w[i] and perm >= 0:
				if w[j + 1] == 'a':
					a += 1
				else:
					b += 1
				j += 1
			elif perm > 0:
				if w[j + 1] == 'a':
					a += 1
				else:
					b += 1
				j += 1
				perm -= 1
			else:
				break
		if j - i + 1 > ans and perm >= 0:
			ans = j - i + 1
		i += 1
print(ans)


import sys
__author__ = 'goran'
(n, k) = map(int, sys.stdin.readline().split())
s = input()
(L, R) = (0, 0)
cnt = [0, 0]
best = 1
while R < n:
	if min(cnt[ord(s[R][0]) - ord('a'[0])] + 1, cnt[1 - ord(s[R][0]) + ord('a'[0])]) > k:
		cnt[ord(s[L][0]) - ord('a'[0])] -= 1
		L += 1
	else:
		cnt[ord(s[R][0]) - ord('a'[0])] += 1
		R += 1
	best = max(best, R - L)
print(best)


(n, k) = map(int, input().split())
s = list(input())
j = 0
answer = 0
counter = [0, 0]
for i in range(n):
	if s[i] == 'b':
		counter[1] += 1
	else:
		counter[0] += 1
	if min(counter) > k:
		if s[j] == 'a':
			counter[0] -= 1
		else:
			counter[1] -= 1
		j += 1
	else:
		answer += 1
print(answer)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 99999999999999999999999999999999

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		(n, k) = ria()
		s = rs()

		def ans(s):
			an = 0
			(i, j) = (0, 0)
			(na, nb) = (0, 0)
			while j < n:
				while min(na, nb) <= k and j < n:
					if s[j] == 'a':
						na += 1
					else:
						nb += 1
					if min(na, nb) <= k:
						an = max(an, j - i + 1)
					j += 1
				while i <= j < n and min(na, nb) > k:
					if s[i] == 'b':
						nb -= 1
					else:
						na -= 1
					i += 1
			return an
		print(ans(s))
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


def longest(s, n, k):
	d = {'a': 0, 'b': 0}
	i = j = m = l = 0
	for i in range(n):
		d[s[i]] = d.get(s[i], 0) + 1
		mm = min(list(d.values()))
		if mm > k:
			while j < n and mm > k:
				d[s[j]] -= 1
				j += 1
				mm = min(list(d.values()))
		elif i - j + 1 > m:
			m = i - j + 1
	return m
while 1:
	try:
		(n, k) = map(int, input().split())
		s = input()
		print(longest(s, n, k))
	except:
		break


(n, k) = input().split()
n = int(n)
k = int(k)
s = list(input())
ans1 = 0
ans2 = 0
a = []
b = []
if k != 0:
	for i in range(n):
		if s[i] == 'a':
			a.append(i)
		else:
			b.append(i)
	if len(a) <= k:
		ans1 = n
	else:
		i = 0
		j = k - 1
		while j < len(a):
			ans = 0
			if i == 0:
				ans += a[i] + 1
			else:
				ans += a[i] - a[i - 1]
			if j == len(a) - 1:
				ans += a[j] - a[i] + n - 1 - a[j]
			else:
				ans += a[j] - a[i] + a[j + 1] - a[j] - 1
			ans1 = max(ans, ans1)
			i += 1
			j += 1
	if len(b) <= k:
		ans2 = n
	else:
		i = 0
		j = k - 1
		while j < len(b):
			ans = 0
			if i == 0:
				ans += b[i] + 1
			else:
				ans += b[i] - b[i - 1]
			if j == len(b) - 1:
				ans += b[j] - b[i] + n - 1 - b[j]
			else:
				ans += b[j] - b[i] + b[j + 1] - b[j] - 1
			ans2 = max(ans, ans2)
			i += 1
			j += 1
	print(max(ans1, ans2))
else:
	ans = 1
	ans1 = 1
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			ans1 += 1
		else:
			ans = max(ans, ans1)
			ans1 = 1
	ans = max(ans, ans1)
	print(ans)


def check(l, r, k, count):
	if l != 0:
		a = count[r][0] - count[l - 1][0]
		b = count[r][1] - count[l - 1][1]
	else:
		a = count[r][0]
		b = count[r][1]
	if a > b and b <= k:
		return a + b
	elif b >= a and a <= k:
		return a + b
	else:
		return 0

def solve_test():
	(n, k) = map(int, input().split())
	string = input()
	count = [(0, 0) for i in range(n)]
	if string[0] == 'a':
		count[0] = (1, 0)
	else:
		count[0] = (0, 1)
	for i in range(1, n):
		if string[i] == 'a':
			count[i] = (count[i - 1][0] + 1, count[i - 1][1])
		else:
			count[i] = (count[i - 1][0], count[i - 1][1] + 1)
	l = 0
	MAXSIZE = 1
	for r in range(1, n):
		c = check(l, r, k, count)
		while l <= r and c == 0:
			l += 1
			c = check(l, r, k, count)
		if l > r:
			l -= 1
		if MAXSIZE < c:
			MAXSIZE = c
	print(MAXSIZE)

def main():
	solve_test()
main()


(n, k) = map(int, input().split())
s = input()
(l, r) = (0, 0)
(a, b) = (0, 0)

def check(l, r, a, b, s):
	while l <= r:
		if min(a, b) <= k:
			return (a, b, l, a + b)
		else:
			if s[l] == 'a':
				a -= 1
			else:
				b -= 1
			l += 1
	return (a, b, l, a + b)
ans = 0
while r < n:
	if s[r] == 'b':
		b += 1
		r += 1
	else:
		r += 1
		a += 1
	t = check(l, r, a, b, s)
	(l, a, b) = (t[2], t[0], t[1])
	ans = max(ans, t[3])
print(ans)


(n, k) = map(int, input().split())
s = input()
count = {'a': s.count('a'), 'b': s.count('b')}
r = n
M = 0
l = 0
while l < n:
	while count['a'] > k and count['b'] > k:
		r -= 1
		count[s[r]] -= 1
	while r < n and (count['a'] <= k or count['b'] <= k):
		count[s[r]] += 1
		r += 1
	if r - l > M:
		if count['a'] > k and count['b'] > k:
			M = r - l - 1
		else:
			M = r - l
	l += 1
	count[s[l - 1]] -= 1
print(M)


from __future__ import division, print_function
from sys import stdin, stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
from fractions import Fraction

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = defaultdict(list)
	for i in range(e):
		(x, y) = mi()
		d[x].append(y)
		d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

def Prime(x):
	if x < 2:
		return False
	for i in range(2, int(sqrt(x)) + 1):
		if x % i == 0:
			return False
	return True
(n, k) = mi()
s = si()
count = 0
(a, b) = (0, 0)
x = 0
for i in range(n):
	if s[i] == 'a':
		a += 1
	else:
		b += 1
	if a <= k or b <= k:
		count += 1
	else:
		if s[x] == 'a':
			a -= 1
		else:
			b -= 1
		x += 1
print(count)


from sys import stdin

def magic(n, k, arr, ch, comp):
	last = 0
	end = -1
	temp = k
	i = 0
	count = 0
	while i < n:
		if arr[i] == ch:
			i += 1
			count = max(count, i - last)
		elif temp > 0:
			temp -= 1
			i += 1
			count = max(count, i - last)
		else:
			end = end + 1
			while arr[end] != comp and end < n:
				end += 1
			last = end + 1
			temp += 1
	return count

def myfunction(n, k, arr):
	return max(magic(n, k, arr, 'a', 'b'), magic(n, k, arr, 'b', 'a'))
(n, k) = list(map(int, stdin.readline().split()))
arr = list(stdin.readline())
print(myfunction(n, k, arr))


(n, k) = list(map(int, input().split()))
s = input()
a = 0
b = 0
p = 0
ind = 0
for i in range(n):
	if s[i] == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) > k:
		if s[p] == 'a':
			a -= 1
		else:
			b -= 1
		p += 1
	else:
		ind += 1
print(ind)


(n, k) = map(int, input().split())
s = input().strip()
ans = 0
l = 0
temp = 0
for r in range(len(s)):
	if s[r] != 'a':
		temp += 1
	while temp > k:
		if s[l] != 'a':
			temp -= 1
		l += 1
	ans = max(ans, r - l + 1)
temp = 0
l = 0
for r in range(len(s)):
	if s[r] != 'b':
		temp += 1
	while temp > k:
		if s[l] != 'b':
			temp -= 1
		l += 1
	ans = max(ans, r - l + 1)
print(ans)


(n, k) = map(int, input().split())
s = list(input())
aa = [0] * (n + 1)
bb = [0] * (n + 1)
res = 1
(a, b) = (0, 0)
for i in range(1, n + 1):
	if s[i - 1] == 'a':
		a += 1
		aa[a] = i
	else:
		b += 1
		bb[b] = i
	res = max(res, i - aa[max(a - k, 0)])
	res = max(res, i - bb[max(b - k, 0)])
print(res)


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)

def bo(i):
	return ord(i) - ord('a')

def can(mid):
	d = [0, 0]
	mini = n
	for i in range(n):
		if i >= mid:
			mini = min(d[0], min(d[1], mini))
			d[bo(a[i - mid])] -= 1
		d[bo(a[i])] += 1
	mini = min(d[0], min(d[1], mini))
	return mini <= k
(n, k) = mi()
a = si()
l = 0
r = ans = n
while l <= r:
	mid = (l + r) // 2
	if can(mid):
		ans = mid
		l = mid + 1
	else:
		r = mid - 1
print(ans)


def troca(x, n, k, s):
	fim = 0
	count = 0
	maxi = 0
	for ini in range(n):
		if s[ini] == x:
			count += 1
		if count > k:
			while fim < n and count > k:
				if s[fim] == x:
					count -= 1
				fim += 1
		maxi = max(maxi, ini - fim + 1)
	return maxi

def main():
	(n, k) = map(int, input().split())
	s = input()
	resposta = max(troca('a', n, k, s), troca('b', n, k, s))
	print(resposta)
main()


(n, k) = map(int, input().split())
s = input()
maxi = res = 0
count = {'a': 0, 'b': 0}
for i in range(n):
	count[s[i]] += 1
	maxi = max(maxi, count[s[i]])
	if res - maxi < k:
		res += 1
	else:
		count[s[i - res]] -= 1
print(res)


(n, k) = map(int, input().split())
a = input()

def solve(x, k):
	(i, j) = (0, 0)
	ans = 0
	t = k
	while i < n and j < n:
		while t >= 0 and j < n:
			if a[j] != x and t >= 1:
				t -= 1
			elif a[j] != x and t == 0:
				break
			j += 1
		ans = max([ans, j - i])
		if a[i] != x:
			t += 1
		i += 1
	return ans
print(max([solve('a', k), solve('b', k)]))


(n, k) = list(map(int, input().split()))
string = list(input())
a = 0
b = 0
limiter = 0
answer = 0
for letter in string:
	if letter == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) > k:
		if string[limiter] == 'a':
			a -= 1
		else:
			b -= 1
		limiter += 1
	else:
		answer += 1
print(answer)


def stringcheckerb(k, n, string):
	l = 0
	r = 0
	bsinstring = 0
	best = 0
	try:
		while True:
			while bsinstring != k + 1:
				r += 1
				if best < r - l + 1:
					best = r - l + 1
				if string[r - 1] == 'b':
					bsinstring += 1
			while bsinstring == k + 1:
				if string[l] == 'b':
					bsinstring -= 1
				l += 1
	except:
		return best

def stringcheckera(k, n, string):
	l = 0
	r = 0
	bsinstring = 0
	best = 0
	try:
		while True:
			while bsinstring != k + 1:
				r += 1
				if best < r - l + 1:
					best = r - l + 1
				if string[r - 1] == 'a':
					bsinstring += 1
			while bsinstring == k + 1:
				if string[l] == 'a':
					bsinstring -= 1
				l += 1
	except:
		return best
a = input('')
b = input('')
string = b
k = 0
n = 0
for i in range(len(a)):
	if a[i] == ' ':
		n = int(a[:i])
		k = int(a[i + 1:])
print(max([stringcheckera(k, n, string), stringcheckerb(k, n, string)]) - 2)


(n, k) = map(int, input().split())
s = input()
d = {'a': 0, 'b': 0}
l = 0
a = 0
for i in s:
	d[i] += 1
	if min(d.values()) > k:
		d[s[l]] -= 1
		l += 1
	else:
		a += 1
print(a)


from sys import stdin
(N, K) = map(int, stdin.readline().split())
charArr = list(stdin.readline().strip())
bad = 0
front = 0
front2 = 0
back = len(charArr)
answer = K
while front < back:
	if charArr[front] != 'a':
		bad += 1
	if bad > K:
		while front2 <= front and charArr[front2] == 'a':
			front2 += 1
		bad -= 1
		front2 += 1
	answer = max(answer, front - front2 + 1)
	front += 1
bad = 0
front = 0
front2 = 0
back = len(charArr)
while front < back:
	if charArr[front] != 'b':
		bad += 1
	if bad > K:
		while front2 <= front and charArr[front2] == 'b':
			front2 += 1
		bad -= 1
		front2 += 1
	answer = max(answer, front - front2 + 1)
	front += 1
print(answer)


def solver(myStr, letter):
	(l, r) = (0, 0)
	(curr_k, best) = (0, 0)
	while r < n:
		if myStr[r] != letter:
			curr_k += 1
		if curr_k <= k:
			best = max(best, r - l + 1)
		else:
			while curr_k > k:
				if myStr[l] != letter:
					curr_k -= 1
				l += 1
		r += 1
	return best
(n, k) = map(int, input().split())
s = input()
print(max(solver(s, 'a'), solver(s, 'b')))


(n, k) = list(map(int, input().split(' ')))
st = input()
(a, b) = (0, 0)
(i, j) = (0, 0)
while i < n:
	while j < n and b <= k:
		if st[j] == 'b':
			b += 1
		j += 1
	if b > k:
		a = max(a, j - i - 1)
	else:
		a = max(a, j - i)
	if st[i] == 'b':
		b -= 1
	i += 1
(aa, ba) = (0, 0)
(ia, ja) = (0, 0)
while ia < n:
	while ja < n and ba <= k:
		if st[ja] == 'a':
			ba += 1
		ja += 1
	if ba > k:
		aa = max(aa, ja - ia - 1)
	else:
		aa = max(aa, ja - ia)
	if st[ia] == 'a':
		ba -= 1
	ia += 1
print(max(a, aa))


def retMaxConsecutive(string, n, k, choice):
	if string.count(choice) <= k:
		return n
	maxi = -1
	index = 0
	count = 0
	for i in range(n):
		if string[i] != choice:
			count += 1
		while count > k and index < n:
			if string[index] != choice:
				count -= 1
			index += 1
		maxi = max(maxi, i - index + 1)
	return maxi
(strLen, maxChange) = input().split(' ')
string = input()
strLen = int(strLen)
maxChange = int(maxChange)
print(max(retMaxConsecutive(string, strLen, maxChange, 'a'), retMaxConsecutive(string, strLen, maxChange, 'b')))


def check(lengths, k, full_count_of_opposite):
	maxcount = 0
	count = 0
	start = 0
	cur_k = k
	for (i, el) in enumerate(lengths):
		if i % 2 == 0:
			count += el
		elif cur_k - el >= 0:
			cur_k -= el
		else:
			maxcount = max(count, maxcount)
			cur_k -= el
			while start < i and cur_k < 0:
				count -= lengths[start]
				cur_k += lengths[start + 1]
				start += 2
			if start > i:
				cur_k = k
				count = 0
	maxcount = max(count, maxcount)
	result = maxcount + min(k, full_count_of_opposite)
	return result

def maxsubsl(s, k):
	lengths = []
	prev = s[0]
	cnt = 0
	full_counts = [0, 0]
	for el in s:
		if el != prev:
			lengths.append(cnt)
			cnt = 0
		prev = el
		cnt += 1
		full_counts[len(lengths) % 2] += 1
	lengths.append(cnt)
	maxl = check(lengths, k, full_counts[1])
	if len(lengths) > 1:
		maxl = max(maxl, check(lengths[1:], k, full_counts[0]))
	return maxl
(_, k) = list(map(int, input().split()))
s = input()
print(maxsubsl(s, k))


(n, k) = map(int, input().split())
string = input()
count = [0, 0]
j = out = 0
for i in range(n):
	count[string[i] == 'a'] += 1
	if min(count) > k:
		count[string[j] == 'a'] -= 1
		j += 1
	else:
		out += 1
print(out)


(n, k) = map(int, input().split())
s = input()
(left, right) = (0, 1)
a = []
b = []
(t1, t2) = (0, 0)
for i in s:
	if i == 'a':
		t1 += 1
	else:
		t2 += 1
	a.append(t1)
	b.append(t2)
temp1 = 0
temp2 = 0
ans = 0
for i in s:
	if i == 'a':
		temp2 = 0
		temp1 += 1
		ans = max(ans, temp1)
	else:
		temp1 = 0
		temp2 += 1
		ans = max(ans, temp2)
while left < n and right < n:
	if left == 0:
		acount = a[right]
		bcount = b[right]
	else:
		acount = a[right] - a[left - 1]
		bcount = b[right] - b[left - 1]
	if acount > k and bcount > k:
		left += 1
	else:
		ans = max(ans, right - left + 1)
		right += 1
print(ans)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007

def solve(a, k):
	pos = []
	res = p = 0
	for i in range(len(s)):
		if s[i] == a:
			if k > 0:
				pos.append(i)
				k -= 1
			else:
				res = max(res, i - p)
				if len(pos):
					p = pos.pop(0) + 1
					pos.append(i)
				else:
					p = i + 1
	return max(res, i - p + 1)
(n, k) = iia()
s = is1()
res = solve('a', k)
res = max(res, solve('b', k))
print(res)


def solve(letter):
	i = 0
	j = 0
	k1 = 0
	while j < n and k1 <= k:
		if s[j] != letter:
			k1 += 1
		if k1 <= k:
			j += 1
	best = j - i
	while i < n and j < n:
		if s[i] != letter:
			i += 1
			if i < n:
				j = max(i, j)
				k1 = k - 1
				while j < n and k1 <= k:
					if s[j] != letter:
						k1 += 1
					if k1 <= k:
						j += 1
				best = max(best, j - i)
		else:
			i += 1
	return best
(n, k) = list(map(int, input().split()))
s = input()
if k == 0:
	last = 0
	best = 1
	for i in range(1, n):
		if s[i] != s[i - 1]:
			best = max(best, i - last)
			last = i
	print(max(best, n - last))
else:
	print(max(solve('a'), solve('b')))


(n, k) = map(int, input().split())
s = input()
(e, t) = (0, 0)
res = 0
for i in range(n):
	if s[i] == 'b':
		t += 1
	while t > k and e < i:
		if s[e] == 'b':
			t -= 1
		e += 1
	res = max(res, i - e + 1)
(e, t) = (0, 0)
for i in range(n):
	if s[i] == 'a':
		t += 1
	while t > k and e < i:
		if s[e] == 'a':
			t -= 1
		e += 1
	res = max(res, i - e + 1)
print(res)


l1 = input().split()
l2 = list(input())
l1 = [int(i) for i in l1]
x = l1[0]
y = l1[1]
j = 0
c = 0
r = 0
for i in range(x):
	if l2[i] == 'a':
		c += 1
	if c > y:
		while c > y:
			if l2[j] == 'a':
				c -= 1
			j += 1
	r = max(r, i - j + 1)
lul = r
j = 0
c = 0
r = 0
for i in range(x):
	if l2[i] == 'b':
		c += 1
	if c > y:
		while c > y:
			if l2[j] == 'b':
				c -= 1
			j += 1
	r = max(r, i - j + 1)
lul = max(lul, r)
print(lul)


(n, k) = map(int, input().split())
text = input() + '0'
forward = dump = 0
if len(text) == 1:
	print(1)
	quit()

def m(a, r):
	begin = 0
	end = 0
	maximum = 0
	while end != len(text) - 1:
		if text[end] != a:
			if r > 0:
				r -= 1
				end += 1
			else:
				while text[begin] == a:
					begin += 1
				begin += 1
				r += 1
		else:
			end += 1
		if end - begin > maximum:
			maximum = end - begin
	return maximum
print(max(m('a', k), m('b', k)))


(n, k) = map(int, input().split())
s = input()
(a, b) = (0, 0)
i = 0
j = 0
ans = 0
curr = 0
while i < n:
	if s[i] == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) <= k:
		ans += 1
	else:
		if s[j] == 'a':
			a -= 1
		else:
			b -= 1
		j += 1
	i += 1
print(ans)


from collections import Counter

def good(s, k, l):
	c = Counter()
	c['a'] = c['b'] = 0
	for i in range(len(s)):
		c[s[i]] += 1
		if i - l >= 0:
			c[s[i - l]] -= 1
		if i + 1 >= l:
			if min(c.values()) <= k:
				return True
	return False

def solve(s, k):
	if good(s, k, len(s)):
		return len(s)
	low = 1
	high = len(s)
	while low + 1 < high:
		mid = (low + high) // 2
		if good(s, k, mid):
			low = mid
		else:
			high = mid
	return low
(n, k) = map(int, input().split())
s = input()
print(solve(s, k))


(n, k) = list(map(int, input().split()))
s = input()
ret = 0
for b in ['a', 'b']:
	l = 0
	r = 0
	curr = k
	while r < n:
		if s[r] == b:
			r += 1
		elif curr > 0:
			r += 1
			curr -= 1
		else:
			if s[l] != b:
				curr += 1
			l += 1
		ret = max(ret, r - l)
print(ret)


import sys
inf = float('inf')
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def solve(char):
	(l, curr, ans) = (0, 0, 0)
	for i in range(n):
		if string[i] != char:
			curr += 1
		while curr > k:
			if string[l] != char:
				curr -= 1
			l += 1
		ans = max(ans, i - l + 1)
	return ans

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, k) = get_ints()
string = input()
ans = max(solve('a'), solve('b'))
print(ans)


(n, k) = map(int, input().split())
s = input()
prefix_a = [0] * (n + 1)
for i in range(1, n + 1):
	if s[i - 1] == 'b':
		prefix_a[i] = 1
	prefix_a[i] = prefix_a[i] + prefix_a[i - 1]
dic = {}
ans = -1
dic.update({0: 0})
for i in range(1, n + 1):
	if prefix_a[i] <= k:
		ans = max(ans, i)
	else:
		last = dic.get(prefix_a[i] - k, -1)
		if last != -1:
			last = dic.get(prefix_a[i] - k)
			ans = max(i - last, ans)
	val = dic.get(prefix_a[i], -1)
	if val == -1:
		dic[prefix_a[i]] = i
prefix_b = [0] * (n + 1)
dic = {}
dic.update({0: 0})
for i in range(1, n + 1):
	if s[i - 1] == 'a':
		prefix_b[i] = 1
	prefix_b[i] = prefix_b[i] + prefix_b[i - 1]
for i in range(1, n + 1):
	if prefix_b[i] <= k:
		ans = max(ans, i)
	else:
		last = dic.get(prefix_b[i] - k, -1)
		if last != -1:
			last = dic.get(prefix_b[i] - k)
			ans = max(i - last, ans)
	val = dic.get(prefix_b[i], -1)
	if val == -1:
		dic[prefix_b[i]] = i
print(ans)


(le, ch) = map(int, input().split())
st = input()
(ca, cb, si, mx) = [0] * 4
for x in st:
	if x == 'a':
		ca += 1
	else:
		cb += 1
	if min(ca, cb) > ch:
		if st[si] == 'a':
			ca -= 1
		else:
			cb -= 1
		si += 1
	else:
		mx += 1
print(mx)


(n, k) = map(int, input().split())
s = list(input())
dp = [[0 for i in range(2)] for i in range(n + 1)]
aNum = 0
bNum = 0
a = []
b = []
for i in range(n):
	if s[i] == 'a':
		aNum += 1
		a.append(i)
		if aNum <= k:
			dp[i + 1][1] = i + 1
		else:
			dp[i + 1][1] = a[aNum - 1] - a[aNum - 1 - k]
		if bNum <= k:
			dp[i + 1][0] = i + 1
		else:
			dp[i + 1][0] = i - b[bNum - 1 - k]
	else:
		bNum += 1
		b.append(i)
		if aNum <= k:
			dp[i + 1][1] = i + 1
		else:
			dp[i + 1][1] = i - a[aNum - 1 - k]
		if bNum <= k:
			dp[i + 1][0] = i + 1
		else:
			dp[i + 1][0] = b[bNum - 1] - b[bNum - 1 - k]
ans = 0
for i in dp:
	ans = max(ans, max(i))
print(ans)


from collections import deque
(n, k) = map(int, input().split())
ab = input()
counter = {'a': deque(), 'b': deque()}
M = 1
for i in range(n):
	counter[ab[i]].append(i)
	inv = 'a' if ab[i] == 'b' else 'b'
	la = len(counter['a'])
	lb = len(counter['b'])
	m = min(la, lb)
	total = la + lb
	if m > k:
		if k == 0:
			counter[inv].clear()
		elif la > lb:
			last = counter['b'].popleft()
			while len(counter['a']) > 0 and counter['a'][0] < last:
				counter['a'].popleft()
		elif lb > la:
			last = counter['a'].popleft()
			while len(counter['b']) > 0 and counter['b'][0] < last:
				counter['b'].popleft()
	elif total > M:
		M = total
print(M)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
from bisect import bisect
s = input()
l1 = []
l2 = []
l3 = []
l4 = []
(c, d) = (0, 0)
for i in range(n):
	if s[i] == 'a':
		l1.append(i)
		d += 1
	else:
		c += 1
		l3.append(i)
	l2.append(c)
	l4.append(d)
if len(l1) != 0 and c != 0:
	ans = 0
	ans1 = 0
	for i in l1:
		a = bisect(l2, l2[i] + k)
		ans = max(ans, a - i)
	for i in l3:
		a = bisect(l4, l4[i] + k)
		ans1 = max(ans1, a - i)
	if l1[0] == 0:
		a = bisect(l4, k)
		ans1 = max(ans1, a)
	if l3[0] == 0:
		a = bisect(l2, k)
		ans = max(ans, a)
else:
	ans = len(s)
	ans1 = len(s)
print(max(ans, ans1))


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
(n, k) = map(int, input().split())
s = input()
(a, b, j) = (0, 0, 0)
for i in range(n):
	if s[i] == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) > k:
		if s[j] == 'a':
			a -= 1
		else:
			b -= 1
		j += 1
print(n - j)


(n, k) = list(map(int, input().split()))
s = input()
t = k
l = 0
ans = 0
for i in range(n):
	if s[i] == 'b':
		t -= 1
	while t < 0:
		if s[l] == 'b':
			t += 1
		l += 1
	ans = max(ans, i - l + 1)
t = k
l = 0
for i in range(n):
	if s[i] == 'a':
		t -= 1
	while t < 0:
		if s[l] == 'a':
			t += 1
		l += 1
	ans = max(ans, i - l + 1)
print(ans)


(n, k) = list(map(int, input().split()))
s = input()
i = 1
j = 0
ca = 0
cb = 0
ans = 1
if s[0] == 'a':
	ca += 1
else:
	cb += 1
while i < len(s):
	if s[i] == 'a':
		ca += 1
	else:
		cb += 1
	if ca > k and cb > k:
		if s[j] == 'a':
			ca -= 1
		else:
			cb -= 1
		j += 1
	if ca <= k or cb <= k:
		ans = max(ans, ca + cb)
	i += 1
print(ans)


def sol(n, k, a, e):
	cnt = 0
	l = 0
	maxl = 0
	for i in range(n):
		if a[i] != e:
			cnt += 1
		while cnt > k:
			if a[l] != e:
				cnt -= 1
			l += 1
		maxl = max(maxl, i - l + 1)
	return maxl
(n, k) = map(int, input().split())
s = input()
maxx = 0
for e in 'ab':
	v = sol(n, k, s, e)
	maxx = max(maxx, v)
print(maxx)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def main():
	(n, k) = map(int, input().split())
	s = input()
	a = []
	for i in s:
		if ord('a') <= ord(i) <= ord('z'):
			a.append(i)
	f = [0, 0]
	s = [0, 0]
	if a[0] == 'a':
		f[1] += 1
	if a[0] == 'b':
		s[1] += 1
	for i in range(1, n):
		f.append(f[i] + (a[i] == 'a'))
		s.append(s[i] + (a[i] == 'b'))
	ans = 0
	for i in range(n):
		l = i
		r = n - 1
		now = i
		while l <= r:
			mid = (r - l) // 2 + l
			if s[mid + 1] - s[i] <= k:
				l = mid + 1
				now = max(now, mid)
			else:
				r = mid - 1
		ans = max(ans, now - i + 1)
		l = i
		r = n - 1
		now = i
		while l <= r:
			mid = (r - l) // 2 + l
			if f[mid + 1] - f[i] <= k:
				l = mid + 1
				now = max(now, mid)
			else:
				r = mid - 1
		ans = max(ans, now - i + 1)
	print(ans)
	return
main()


(n, k) = map(int, input().split())
s = input()
mx = 0
ac = 0
bc = 0
j = 0
for i in range(len(s)):
	if s[i] == 'a':
		ac += 1
	elif s[i] == 'b':
		bc += 1
	if ac - k <= 0 or bc - k <= 0:
		mx = ac + bc
	else:
		if s[j] == 'a':
			ac -= 1
		else:
			bc -= 1
		j += 1
print(mx)


(n, k) = map(int, input().split())
s = list(input())
(a, b) = ([], [])
for i in range(n):
	if s[i] == 'a':
		a.append(i)
	else:
		b.append(i)
a = [-1] + a + [n]
b = [-1] + b + [n]
res = 0
if len(a) <= k + 2 or len(b) <= k + 2:
	print(n)
else:
	for i in range(1, len(a) - k):
		res = max(res, a[i + k] - 1 - (a[i - 1] + 1) + 1)
	for i in range(1, len(b) - k):
		res = max(res, b[i + k] - 1 - (b[i - 1] + 1) + 1)
	print(res)


(n, k) = map(int, input().split())
(s, ans) = (input(), 0)
for j in ['a', 'b']:
	(b, c, p1, p2) = ([], k, 0, 0)
	for i in range(n):
		if s[i] == j:
			b.append(i)
			if c:
				c -= 1
			else:
				p1 = b[p2] + 1
				p2 += 1
		ans = max(ans, i - p1 + 1)
print(ans)


def check(m):
	if min(a[m - 1], b[m - 1]) <= k:
		return True
	for i in range(1, n - m + 1):
		(na, nb) = (a[i + m - 1] - a[i - 1], b[i + m - 1] - b[i - 1])
		if min(na, nb) <= k:
			return True
	else:
		return False
(n, k) = map(int, input().split())
s = input()
(a, b) = ([0] * (n + 1), [0] * (n + 1))
for i in range(n):
	if s[i] == 'a':
		a[i + 1] += a[i] + 1
		b[i + 1] = b[i]
	else:
		b[i + 1] += b[i] + 1
		a[i + 1] = a[i]
a.pop(0)
b.pop(0)
(l, r, ans) = (1, n, 0)
while l <= r:
	m = (l + r) // 2
	if check(m):
		l = m + 1
		ans = m
	else:
		r = m - 1
print(ans)


(n, k) = map(int, input().split())
st = input()
count = [0, 0]
j = ans = 0
for i in range(n):
	count[st[i] == 'a'] += 1
	if min(count) > k:
		count[st[j] == 'a'] -= 1
		j += 1
	else:
		ans += 1
print(ans)


(n, k) = map(int, input().split())
string = str(input())
a = b = start = res = 0
for i in range(n):
	if string[i] == 'a':
		a += 1
	else:
		b += 1
	if min(a, b) > k:
		if string[start] == 'a':
			a -= 1
		else:
			b -= 1
		start += 1
	else:
		res += 1
print(res)


(n, k) = map(int, input().split())
(a, b) = (0, 0)
ma = 0
i2 = 0
st = input()
if st[0] == 'a':
	a += 1
else:
	b += 1
for i1 in range(n):
	while min(a, b) <= k and i2 < n - 1:
		i2 += 1
		if st[i2] == 'a':
			a += 1
		else:
			b += 1
	if min(a, b) > k:
		if st[i2] == 'a':
			a -= 1
		else:
			b -= 1
		i2 -= 1
	ma = max(ma, a + b)
	if st[i1] == 'a':
		a -= 1
	else:
		b -= 1
print(ma)


(N, T) = map(int, input().split())
S = input()
a = 0
b = 0
r = 0
l = 0
mx = 0
while r < N:
	if S[r] == 'a':
		mx = max(mx, r - l + 1)
	else:
		b += 1
	if b <= T:
		mx = max(mx, r - l + 1)
	while b > T:
		if S[l] == 'b':
			b -= 1
		l += 1
	r += 1
a = 0
b = 0
r = 0
l = 0
while r < N:
	if S[r] == 'b':
		mx = max(mx, r - l + 1)
	else:
		a += 1
	if a <= T:
		mx = max(mx, r - l + 1)
	while a > T:
		if S[l] == 'a':
			a -= 1
		l += 1
	r += 1
print(mx)


(n, k) = list(map(int, input().split()))
s = input()
l = 0
f = 0
g = 0
m = 0
i = 0
while i < n:
	while min(f, g) <= k and i < n:
		if s[i] == 'a':
			f += 1
		else:
			g += 1
		i += 1
	if i == n and min(f, g) <= k:
		m = max(i - l, m)
	else:
		m = max(i - l - 1, m)
	if s[l] == 'a':
		f -= 1
	else:
		g -= 1
	l += 1
print(m)


def find_max(n, k, s, char='a'):
	l = 0
	r = 0
	num = 0
	ans = 0
	cnt = 0
	while r < n:
		if s[r] != char and num < k:
			cnt += 1
			num += 1
			r += 1
		elif s[r] == char:
			cnt += 1
			r += 1
		elif s[r] != char and num >= k:
			ans = max(ans, cnt)
			if l == -1:
				l += 1
			else:
				if s[l] != char:
					num -= 1
				l += 1
				cnt -= 1
	ans = max(cnt, ans)
	return ans
(n, k) = map(int, input().split())
s = input()
ans = max(find_max(n, k, s), find_max(n, k, s, 'b'))
print(ans)


(n, k) = list(map(int, input().split()))
s = input()
l = 0
r = 0
maxi = {'a': 0, 'b': 0}
cur = {'a': 0, 'b': 0}
while r < n:
	if min(cur.values()) > k:
		maxi['a'] = max(maxi['a'], cur['a'] + k)
		maxi['b'] = max(maxi['b'], cur['b'] + k)
		cur[s[l]] -= 1
		l += 1
		continue
	cur[s[r]] += 1
	r += 1
maxi['a'] = max(maxi['a'], cur['a'] + k)
maxi['b'] = max(maxi['b'], cur['b'] + k)
res = max(maxi.values())
res = min(n, res)
print(res)


from collections import deque
(n, k) = map(int, input().split())
s = input()
repl = deque()
sub = 0
current = 0
if n == 1:
	print(1)
	exit()
if k == 0:
	for i in range(n):
		if s[i] == 'a':
			current += 1
		else:
			sub = max(sub, current)
			current = 0
	sub = max(sub, current)
	current = 0
	for i in range(n):
		if s[i] == 'b':
			current += 1
		else:
			sub = max(sub, current)
			current = 0
	sub = max(sub, current)
	print(sub)
	exit()
for i in range(n):
	if s[i] == 'a':
		current += 1
	elif len(repl) < k:
		current += 1
		repl.append(i)
	else:
		sub = max(sub, current)
		current = i - repl[0]
		repl.popleft()
		repl.append(i)
sub = max(sub, current)
current = 0
repl = deque()
for i in range(n):
	if s[i] == 'b':
		current += 1
	elif len(repl) < k:
		current += 1
		repl.append(i)
	else:
		sub = max(sub, current)
		current = i - repl[0]
		repl.popleft()
		repl.append(i)
sub = max(sub, current)
print(sub)


def main():
	(n, k) = map(int, input().split())
	(s, x) = (input(), 2)
	if not k < s.count('a') < n - k:
		print(n)
		return
	for a in ('a', 'b'):
		(j, cnt) = (-1, k)
		try:
			for (i, c) in enumerate(s):
				if c != a:
					if cnt:
						cnt -= 1
					else:
						if x < i - j:
							x = i - j
						j += 1
						while s[j] == a:
							j += 1
		except IndexError:
			pass
		else:
			if x < n - j:
				x = n - j
	print(x - 1)
main()


(n, k) = list(map(int, input().split()))
s = input()
left = 0
changes = 0
record_a = 0
for i in range(len(s)):
	if s[i] == 'b':
		changes += 1
		if changes > k:
			changes -= 1
			while s[left] == 'a':
				left += 1
			left += 1
	record_a = max(record_a, i + 1 - left)
left = 0
changes = 0
record_b = 0
for i in range(len(s)):
	if s[i] == 'a':
		changes += 1
		if changes > k:
			changes -= 1
			while s[left] == 'b':
				left += 1
			left += 1
	record_b = max(record_b, i + 1 - left)
print(max(record_a, record_b))


from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
import math

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def divs(n, start=2):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors
import sys
inf = float('inf')
mod = 1000000007

def array():
	return list(map(int, sys.stdin.readline().split()))

def intt():
	return map(int, sys.stdin.readline().split())
from bisect import bisect_left
import sys
(n, k) = intt()
s = input()
ptr = 0
a = 0
b = 0
ans = 0
for i in range(n):
	if s[i] == 'a':
		a += 1
	else:
		b += 1
	while min(a, b) > k:
		if s[ptr] == 'a':
			a -= 1
		else:
			b -= 1
		ptr += 1
	ans = max(ans, i - ptr + 1)
print(ans)