#include <bits/stdc++.h>
using namespace std;
int n, ans, dp[10000][10000];
string s;
int main(){
    cin >> n >> s;
    for (int i=1; i<=n; i++){
        for (int j=i+1; j<=n; j++){
            if (s[i-1] == s[j-1]){
                if (j - dp[i-1][j-1] == i)dp[i][j] = 0;
                else{
                    dp[i][j] = dp[i-1][j-1] + 1;
                    ans = max(ans, dp[i][j]);
                }
            }
        }
    }
cout << ans;
return 0;
}