#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef long double ld;
using namespace std;
int main() {
IO
int n, ans = 0;
string s, tmp;
cin >> n >> s;
tmp = s[0] + s[n - 1];
if (s.find(tmp) != -1) {
cout << ans;
} else {
if (s[0] == s[n - 1]) {
cout << n - 1;
} else {
cout << n - 2;
}
}
return 0;
}