/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    vector<ll> v(n,0);
    ll p = 37;
    v[0] = s[0];
    for(ll i=1;i<n;i++)
    {
        v[i] = (p*v[i-1])%M;
        v[i] = (v[i] + s[i])%M;
    }
    vector<ll> calculate(n+1,1);
    calculate[0] = 1;
    for(ll i=1;i<=n;i++)
    {
        calculate[i] = (calculate[i-1]*p)%M;
    }
    ll p1 = 26;
    ll M1 = 1180637;
    vector<ll> calculate1(n+1,1);
    vector<ll> v1(n,0);
    v1[0] = s[0];
    for(ll i=1;i<n;i++)
    {
        v1[i] = (p1*v1[i-1])%M1;
        v1[i] = (v1[i] + s[i])%M1;
    }
    for(ll i=1;i<=n;i++)
    {
        calculate1[i] = (calculate1[i-1]*p1)%M1;
    }
    ll be = 1;
    ll en = n/2;
    ll ans=0;
    while(be<=en)
    {
        ll mid = (be+en)/2;
        ll i=0;
        ll j=mid-1;
        bool flag=0;
        while(j<n)
        {
            ll hv = (v[j]);
            ll hv1 = v1[j];
            if(i>0)
            {
                ll y = calculate[j-i+1];
                ll y1 = calculate1[j-i+1];
                y = (y*v[i-1])%M;
                y1 = (y1*v1[i-1])%M1;
                hv = (hv-y+M)%M;
                hv1 = (hv1-y1+M1)%M1;
            }
            ll start = j+1;
            ll end = j+mid;
            while(end < n)
            {
                ll temp = v[end];
                ll temp1 = v1[end];
                if(start>0)
                {
                    ll y = calculate[end-start+1];
                    ll y1 = calculate1[end-start+1];
                    y = (y*v[start-1])%M;
                    y1 = (y1*v1[start-1])%M1;
                    temp = (temp-y+M)%M;
                    temp1 = (temp1-y1+M1)%M1;
                }
                if(temp==hv && temp1==hv1)
                {
                    flag=1;
                    break;
                }
                start++;
                end++;
            }
            if(flag)
            {
                break;
            }
            i++;
            j++;
        }
        if(flag)
        {
            ans = mid;
            be=mid+1;
        }
        else
        {
            en=mid-1;
        }
    }
    cout<<ans;
    return 0;
}




Measured memory_bytes: 384