k = int(input())
string = input()
zero_one = ""
l = []
for each in string:
if 65 <= ord(each) <= 90:
zero_one += "0"
elif 97<= ord(each) <= 122:
zero_one += "1"
test = ""
total = 0
for each in zero_one:
if test == "":
test = each
total += 1
elif test == each:
total += 1
else:
l.append(total)
total = 1
test = each
l.append(total)
def find(k,n):
global leng
if n == len(l):
pass
elif l[n] > k:
if leng == 0:
leng += k
find(k,n+1)
else:
leng += k
elif l[n] == k:
leng += k
find(k,n+1)
maxleng = 0
for i in range(len(l)):
leng = 0
find(k,i)
if leng>maxleng:
maxleng = leng
print(maxleng)