#include <iostream>
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod = 1e9 + 7;
const ll mod2 = 1e9 + 9 ;
using namespace std;
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};
void add2(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod2;
} 
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ll mul2(ll a , ll b){
	return (a * b) % mod2;
}
ll Pow(ll a , ll b){
	if(b == 0) return 1 ;
	ll c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c)% mod )) % mod ;
	return (c * c) % mod ;
}
ll Pow2(ll a , ll b){
	if(b == 0) return 1 ;
	ll c = Pow2(a , b / 2) ;
	if(b % 2) return (a * ((c * c)% mod2 )) % mod2 ;
	return (c * c) % mod2 ;
}
struct state {
	int len , link ;
	map<char , int> next ;
} ;
const int MAXLEN = 5e3 + 5 ;
vector<state> st(2 * MAXLEN) ;
int sz , last ;
void sa_init(){
	st[0].len = 0 ;
	st[0].link = -1 ;
	sz++ ;
	last = 0 ;
}
void sa_extend(char c){
	int cur = sz++ ;
	st[cur].len = st[last].len + 1 ;
	int p = last ;
	while(p != -1 && !st[p].next.count(c)){
		st[p].next[c] = cur ;
		p = st[p].link ;
	}
	if(p == -1){
		st[cur].link = 0 ;
	}
	else{
		int q = st[p].next[c] ;
		if(st[p].len + 1 == st[q].len){
			st[cur].link = q ;
		}
		else{
			int clone = sz++ ;
			st[clone].len = st[p].len + 1 ;
			st[clone].next = st[q].next ;
			st[clone].link = st[q].link ;
			while(p != -1 && st[p].next[c] == q){
				st[p].next[c] = clone ;
				p = st[p].link ;
			}
			st[q].link = st[cur].link = clone ;
		}
	}
	last = cur ;
}
string lcs (string S, string T) {
    //sa_init();
    /*for (int i = 0; i <(int) S.size(); i++)
        sa_extend(S[i]);*/

    int v = 0, l = 0, best = 0, bestpos = 0;
    for (int i = 0; i <(int) T.size(); i++) {
        while (v && !st[v].next.count(T[i])) {
            v = st[v].link ;
            l = st[v].len ;
        }
        if (st[v].next.count(T[i])) {
            v = st [v].next[T[i]];
            l++;
        }
        if (l > best) {
            best = l;
            bestpos = i;
        }
    }
    return T.substr(bestpos - best + 1, best);
} 
int main(){
	IOS;
	cout.precision(50) ;
	int n ;cin >> n ;string s ;
	cin >> s;
	vector<pair<string , string>> v;
	for(int i = 0 ; i < n - 1; i++){
		string s1 ="" ;
		for(int j = 0 ; j <= i ; j++) s1 += s[j] ;
		string s2= "" ;
		for(int j = i + 1 ; j < n ; j++) s2 += s[j] ;
		v.pb(mp(s1 , s2)) ;
	}
	int ans = 0 ;
	int i = 0 ;
	sa_init() ;
	for(pair<string , string> p:v){
		sa_extend(s[i]) ;
		ans = max(ans ,(int) lcs(p.x , p.y).size()) ;
		i++ ;
		
		//cout << ans << endl; 
	}
	cout << ans << endl ;
	return 0;
}


Measured memory_bytes: 52460