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

int main(){
    int N; cin >> N;
    string s; cin >> s;
    int dp[N+1][N+1];
    memset(dp,0,sizeof(dp));
    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(s[i]==s[j]){
                dp[i+1][j+1]=dp[i][j]+1;
            }
            ans=max(ans,min(j-i,dp[i+1][j+1]));
        }
    }
    cout << ans << endl;
}