rt
#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const int N=500005,base=237;
int n;
string s;
int dp[N];
vector<int> vec[2];
ull qarr[N],pw[N];
inline int get(int l,int r) {
return qarr[r]-qarr[l-1]*pw[r-l+1];
}
int ans=0,siz;
int main() {
cin >> n >> s;
s=' '+s;
pw[0]=1;
for(int i=1;i<=n;++i) pw[i]=pw[i-1]*base;
for(int i=1;i<=n;++i) qarr[i]=(qarr[i-1]*base)+s[i]-'a'+1;
int l,r,p;bool op=0;
for(int i=1;i<=1000;++i) { // 枚举答案长度
unordered_map<ull,bool> Hash;Hash[0]=1;
op=!op,p=0;
siz=vec[!op].size();
for(int j=n-i+1;j>=1;--j) {
l=j,r=j+i-1;
while(p<siz && vec[!op][p]>r) {
Hash[get(vec[!op][p],vec[!op][p]+i-2)]=1;
++p;
}
if(Hash[get(l,r-1)] || Hash[get(l+1,r)]) {
vec[op].push_back(l);
}
}
vec[!op].clear();
if(vec[op].size()) ans=i;
else break;
}
cout << ans;
return 0;
}