#include <bits/stdc++.h>
using namespace std;

#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)

bool isupper(char c){
	if(c>='A'&&c<='Z')return 1;
	else return 0;
}

int main(){
	IOS();
	int k;cin>>k;
	vector <int> v;
	string s;cin>>s;	
	int slen = (int)s.size(),now = 1;
	//string to int array	
	for(int i=1;i<slen;i++){
		if( isupper(s[i])==isupper(s[i-1]) )now++;
		else {
			v.pb(now);
			now = 1;
		}
	}
	v.pb(now);
	v.pb(0);
	//find ans
	int vlen = (int)v.size();
	vector <int> ans;
	now = 0;
	bool flag = 0;
	for(int i=0;i<vlen;i++){
		if(v[i]>=k && flag==0){
			now += k;
			flag = 1;
		}
		else if(v[i]==k){
			now += k;
		}
		else if(v[i]>=k && flag==1){
			now += k;
			i--;		
			ans.pb(now);
			flag = 0;
			now = 0;
		}
		else if(v[i]<k){
			ans.pb(now);
			now = 0;
		}
	}
	sort(ALL(ans));
	//output
	cout<<ans[ans.size()-1]<<endl;
	return 0;
}

ZJ

pixiv