#include<bits/stdc++.h>
using namespace std;

const int key = 233;
const int md = 1e9 + 7;
const int key2 = 131;
const int md2 = 1e9 + 9;

const int N = 4e5 + 5;

int step[N + 5], step2[N + 5], sh[N], sh2[N], obr[N], obr2[N], n;
string s;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    step[0] = step2[0] = 1;
    for (int i = 1; i < N + 5; ++i){
        step[i] = (1ll * step[i - 1] * key) % md;
        step2[i] = (1ll * step2[i - 1] * key2) % md2;
    }
    cin >>n;
    cin >>s;
    s = "." + s;
    for (int i = 1; i <= n; ++i){
        sh[i] = (sh[i - 1] + 1ll * s[i] * step[i - 1]) % md;
        sh2[i] = (sh2[i - 1] + 1ll * s[i] * step2[i - 1]) % md2;
    }
    for (int i = n; i >= 1; --i){
        obr[i] = (obr[i + 1] + 1ll * s[i] * step[n - i]) % md;
        obr2[i] = (obr2[i + 1] + 1ll * s[i] * step2[n - i]) % md2;
    }
    for (int i = 1; i <= n; ++i){
        int l = i, r = n;
        long long x = sh[r] - sh[l - 1];
        if (x < 0)x += md;
        x = (1ll * x * step[N - (r - 1)]) % md;
        long long y = (1ll * obr[l] * step[N - (n - l)]) % md;
        if (x != y)continue;

        x = sh2[r] - sh2[l - 1];
        if (x < 0)x += md2;
        x = (1ll * x * step2[N - (r - 1)]) % md2;
        y = (1ll * obr2[l] * step2[N - (n - l)]) % md2;
        if (x != y)continue;
        cout <<i - 1;
        return 0;
    }
}

