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

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