#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+1;
void solve(){
int n;
cin>>n;
string s;
cin>>s;
if(s[0] == s[n-1])
cout<<n-1;
else
cout<<n-2;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
#endif
int tt=1;//cin>>tt;
while(tt--)
solve();
}