#include <iostream>
#include <memory.h>

using namespace std;

typedef long long LL;
LL process[5003];
LL base[5003];
LL mod=10007;
LL basic=31;
LL store[10007];

void haxi(string &s)
{
    process[0]=0;
    base[0]=1;
    for(int i=0;s[i]!='\0';i++)
    {
        process[i+1]=((process[i]*basic)%mod+s[i])%mod;
        base[i+1]=(base[i]*basic)%mod;
    }
}

LL gethash(int l,int r)
{
    return (process[r]+mod-(process[l-1]*base[r-l+1])%mod)%mod;
}

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    haxi(s);

    int len;
    for(len=1;len<=n/2;len++)
    {
        int count=0,mark=0;
        memset(store,0,sizeof(store));
        for(int i=1;i+len-1<=n;i++)
        {
            store[gethash(i,i+len-1)]++;   
        }
        for(int i=0;i<10007;i++)
        {
            if(store[i]>1) mark=1;
        }
        if(mark==0)
        {
            cout<<len-1;
            return 0;
        }
    }
    cout<<len-1;

    return 0;
}