#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
string a;
cin>>a;
stack<char> e;
int ans=0;
for(int i=0;i<n;i++){
if(e.empty()&&(a[i]=='a'||a[i]=='h')){
e.push(a[i]);
}
else if(!e.empty()){
if(e.top()=='a'){
if(a[i]=='h'){
e.push(a[i]);
}
else{
ans=max(ans,int(e.size()));
while (!e.empty()){
e.pop();
}
if(a[i]=='a'){
e.push(a[i]);
}
}
}
else if(e.top()=='h'){
if(a[i]=='a'){
e.push(a[i]);
}
else{
ans=max(ans,int(e.size()));
while (!e.empty()){
e.pop();
}
if(a[i]=='h'){
e.push(a[i]);
}
}
}
}
}
ans=max(ans,int(e.size()));
cout<<ans;
return 0;
}