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

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans = 0;
    for(int d = 0; d < N; ++d) {
        int cnt = 0;
        for(int i = 0; i < N - d; ++i) {
            if(S[i] == S[i+d]) {
                ++cnt;
            } else {
                cnt = 0;
            }
            ans = max(ans, min(d, cnt));
        }
    }
    cout << ans << endl;
    return 0;
}