#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int main(){
    int n, ans = 0;
    cin >> n;
    string s;
    cin >> s;
    for(int i=1;i<=n;i++) {
        int len = 0;
        for(int j=0;j+i<n;j++) {
            if(s[j] == s[j+i]) {
                if(len < i)
                    len++;
                ans = max(ans, len);
            }
            else
                len = 0;
        }
    }
    cout << ans << endl;
}
