#include using namespace std; const int N = 4e5+5; const long long A = 911382323; const long long B = 972663749; const long long C = 1e9+7; const long long D = 1e9+9; #define ll long long int n; string s; long long p[N]; long long r[N]; int sol1(string q) { long long h = 0; set sh; for (int i = 0; i < n; ++i) { h = (h + ((ll)q[i]*p[i])%B)%B; //cout << h << ' ' << q[i] << endl; sh.insert(h); } //cout << endl; h = 0; int ans = 0; for (int i = 0; i < n; ++i) { h = ((h*A)%B + (ll)q[i])%B; //cout << h << ' ' << q[i] << endl; if (sh.count(h)) { ans = max(ans, i); } } return ans; } int sol2(string q) { long long h = 0; set sh; for (int i = 0; i < n; ++i) { h = (h + ((ll)q[i]*r[i])%D)%D; //cout << h << ' ' << q[i] << endl; sh.insert(h); } //cout << endl; h = 0; int ans = 0; for (int i = 0; i < n; ++i) { h = ((h*C)%D + (ll)q[i])%D; //cout << h << ' ' << q[i] << endl; if (sh.count(h)) { ans = max(ans, i); } } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); r[0] = p[0] = 1; for (int i = 1; i < N; ++i) { p[i] = (p[i-1]*A)%B; r[i] = (r[i-1]*C)%D; } cin >> n >> s; string q(s.rbegin(), s.rend()); int ans = sol1(q); int ans2 = sol2(q); string t = s; for (int i = ans+1; i < n; ++i) { t.push_back(q[i]); } string u = s; for (int i = ans2+1; i < n; ++i) { u.push_back(q[i]); } //cout << t << endl << u << endl; string sadf(t.rbegin(), t.rend()); if (t != sadf) { ans = -1; } string gffg(u.rbegin(), u.rend()); if (u != gffg) { ans2 = -1; } cout << n-max(ans, ans2)-1; return 0; }