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

int main()
{
    int N;
    string S;
    cin >> N >> S;

    int ans = 0;
    for (int diff = 0; diff < N; diff++)
    {
        int match = 0;
        for (int i = 0; i + diff < N; i++)
        {
            if (S[i] == S[diff + i])
            {
                match++;
            }
            else
            {
                match = 0;
            }
            ans = max(ans, min(match, diff));
        }
    }
    cout << ans << endl;
}
