#31567: Python Regex解法


seer852741@gmail.com (St418)


from re import findall

k = int(input())
text = input()

pattern = fr'(?=((?:[a-z]{{{k}}})?(?:[A-Z]{{{k}}}[a-z]{{{k}}})*(?:[A-Z]{{{k}}})?))'

result = findall(pattern, text)
print(max(map(len, result)))