#include<iostream>
#include<math.h>
#include<queue>
#include<string>
using namespace std;
int main(){
	int n;cin>>n;
	string s;cin>>s;
	int ans=0;
	for(int i=0;i<n;i++){
		int hoge=0;
		for(int j=0;j+i+1<n;j++){
			if(s[j]==s[j+i+1]){hoge++;}
			else{ans=max(ans,min(hoge,i+1));hoge=0;}
		}
		ans=max(ans,min(hoge,i+1));
	}
	cout<<ans<<endl;
}