#include <bits/stdc++.h>
#define ll long long
#define mk make_pair
#define pb push_back
using namespace std;
ll mod = 1000000007;
void solve(){
int n ; cin >> n;
string s;
cin >> s;
if(s[0] == s[n-1]){
cout << n-1 ;
}
else{
cout << max(0 , n - 2) ;
}
}
int main(){
int t = 1 ;
//cin >> t ;
while(t--){
solve();
}
return 0;
}