#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
string S;
int N;
int f(string & s1, string & s2) {
    int maxcase_off1=0;
    int maxcase_off2=0;
    int maxcase_len=0;
    //cout << s1 << " " << s2 << endl;
    for(int off = -(int)s1.size(); off <= (int)s2.size(); off++) {
        int len = 0;
        for(int i = max(off, 0); i <= min(s1.size()+off, s2.size()); i++) {
            if(len > maxcase_len) {
                maxcase_off1 = i-len-off;
                maxcase_off2 = i-len;
                maxcase_len = len;
            }
            if(s1[i-off] != s2[i]) {
                len = 0;
            } else {
                len++;
            }
        }
    }
    return maxcase_len;
}

int binary_search(int x0, int x3) {
    int ans = 0;
    while(x3 - x0 > 8) {
        int diff = (x3 - x0) / 9;
        int x1 = x0 + diff;
        int x2 = x3 - diff;
        //cout << x0 << " " << x1 << " " << x2 <<  " " << x3 << endl;
        string s1 = S.substr(0, x1 + 1), s2 = S.substr(x1 + 1);
        string t1 = S.substr(0, x2 + 1), t2 = S.substr(x2 + 1);
        int value1 = f(s1, s2);
        int value2 = f(t1, t2);
        if (value1 < value2) 
            x0 = x1;
        else 
            x3 = x2;
        ans = max(ans, max(value1, value2));
    }
    REP(i, x0, x3) {
        string s1 = S.substr(0, i), s2 = S.substr(i);
        int value1 = f(s1, s2);
        ans = max(ans, value1);
    }
    REP(i, 0, min(N - 1, 10)) {
        string s1 = S.substr(0, i), s2 = S.substr(i);
        int value1 = f(s1, s2);
        ans = max(ans, value1);
    }
    REP(i, max(0,N - 10), N - 1) {
        string s1 = S.substr(0, i), s2 = S.substr(i);
        int value1 = f(s1, s2);
        ans = max(ans, value1);
    }
    return ans;

}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    cin >> S;
    string s1, s2 = S;
    if (N >= 500) {
    cout << binary_search(0, N - 1) << endl;
    return 0;
    }
    int ans = 0;
    ///*
    rep(i, N - 1) {
        s1 = S[N - i - 1] + s1;
        s2.pop_back();
        int maxcase_off1=0;
        int maxcase_off2=0;
        int maxcase_len=0;
        //cout << s2 << " " << s1 << endl;
        for(int off = -(int)s1.size(); off <= (int)s2.size(); off++) {
            int len = 0;
            for(int i = max(off, 0); i <= min(s1.size()+off, s2.size()); i++) {
                if(len > maxcase_len) {
                    maxcase_off1 = i-len-off;
                    maxcase_off2 = i-len;
                    maxcase_len = len;
                }
                if(s1[i-off] != s2[i]) {
                    len = 0;
                } else {
                    len++;
                }
            }
        }
        //cout << s1.substr(maxcase_off1, maxcase_len) << endl;
        ans = max(ans, maxcase_len);
    }
    cout << ans << endl;
    //*/
    return 0;
}


Measured memory_bytes: 384