k=int(input()) s=input() times=[] def init(): u=l=0 last_is_upper=last_is_lower=False if s[0].isupper(): last_is_upper=True u+=1 else: last_is_lower=True l+=1 for i in s[1:]: if last_is_upper: if i.isupper(): u+=1 last_is_upper=True else: times.append(u) u=0 l+=1 last_is_upper=False last_is_lower=True elif last_is_lower: if i.islower(): l+=1 last_is_lower=True else: times.append(l) l=0 u+=1 last_is_lower=False last_is_upper=True if l>0: times.append(l) elif u>0: times.append(u) def find_max_length(): max_length=cur_length=0 for i in times: if i==k: cur_length+=k elif i<k: max_length=max(max_length,cur_length) cur_length=0 elif i>k: cur_length+=k max_length=max(max_length,cur_length) cur_length=k max_length=max(max_length,cur_length) return max_length init() print(find_max_length())