#include<bits/stdc++.h>//請問我的程式錯在哪裡
using namespace std;
int main()
{
int k;
while(cin>>k)
{
string a;
cin>>a;
int count=0,big=0;
int hl;
bool b=0;
int tmp;
hl=a.length();
for(int i=0;i<hl-k+1;i++)
{
b=0;
if(isupper(a[i]))
{
b=1;
}
for(int j=i;j<i+k;j++)
{
if(isupper(a[j])!=b)
{
break;
}
if(j==(i+k-1))
{
count=k;
b=1-b;
tmp=j;
j++;
while(isupper(a[j])==b)
{
if((j-tmp)%k==0)
{
b=1-b;
count+=k;
}
if(j>=hl-1)
break;
j++;
}
}
if(big<count)
big=count;
count=0;
}
}
cout<<big<<"\n";
}
return 0;
}